티스토리 뷰

순열 구하기

모든 경우의 수

import itertools as it

n = 3
a = list(range(1, n+1))
# 리스트 a로 만들 수 있는 모든 순열의 경우 tuple 형태로 출력
for tmp in it.permutations(a):
    print(tmp)

# (1, 2, 3)
# (1, 3, 2)
# (2, 1, 3)
# (2, 3, 1)
# (3, 1, 2)
# (3, 2, 1)
for tmp in it.permutations([1, 2, 3], 2):
    print(tmp)

# (1, 2)
# (1, 3)
# (2, 1)
# (2, 3)
# (3, 1)
# (3, 2)

조합 구하기

중복 제거

import itertools as it

for tmp in it.combinations([1, 2, 3], 2):
    print(tmp)
    
# (1, 2)
# (1, 3)
# (2, 3)
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함