파이썬 순열/조합

Eungho won·2022년 9월 21일
0

코딩테스트

목록 보기
4/4

순열(Permutation)

from itertools import permutations
before = [3,1,2]
after = permutations(before,2)
print(list(after))
# [(3, 1), (3, 2), (1, 3), (1, 2), (2, 3), (2, 1)]
# 경우의 수 = P(3,2)

조합(Combiation)

from itertools import combinations
before = [3,1,2]
after = combinations(before,2)
print(list(after))
#[(3, 1), (3, 2), (1, 2)]

관련 공식 : https://coding-factory.tistory.com/606

profile
kill to code

0개의 댓글