2022-02-21 TIL

Grolar Kim·2022년 2월 21일
0

TIL-WIL

목록 보기
3/17

파이썬으로 순열과 조합 등의 경우의 수를 알기 위해서는 내장 라이브러리인 itertools의 permutation과 combination을 사용하면 된다.

순열 Permutations

순열이란 서로 다른 n개중에 r개를 선택하는 경우의 수를 의미합니다. (순서 상관 있음)
https://docs.python.org/3/library/itertools.html?highlight=itertools#itertools.permutations

# permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
# permutations(range(3)) --> 012 021 102 120 201 210

조합 Combinations

조합이란 서로 다른 n개중에 r개를 선택하는 경우의 수를 의미합니다. (순서 상관 없음)
https://docs.python.org/3/library/itertools.html?highlight=itertools#itertools.combinations

# combinations('ABCD', 2) --> AB AC AD BC BD CD
# combinations(range(4), 3) --> 012 013 023 123

0개의 댓글