본문 바로가기
백준 - python 개념 정리

python - 순열과 조합 빠르게 해결하는 방법

by 반오십 코린이 2023. 6. 30.
728x90

순열 빠르게 뽑는 방법

from itertools import permutations
p = permutations(range(1,4), 2) #1~3까지 2가지 뽑기
for i in p:
    print(" ".join(map(str,i)))


조합 빠르게 뽑는 방법

from itertools import combinations
p = combinations(range(1,4), 2) #1~3까지 2가지 뽑기
for i in p:
    print(" ".join(map(str,i)))

728x90