코딩테스트 준비/[python 알고리즘]
[python 알고리즘] itertools를 이용하여 순열, 조합 구현
bled
2021. 5. 19. 16:11
https://juhee-maeng.tistory.com/91?category=922562
(Python) 순열, 조합, 중복순열, 중복조합 쉽게 구현하기
(Python) 순열, 조합, 중복순열, 중복조합 구현하기 (Python) 순열, 조합 쉽게 만들기¶ 결론부터 말하자면, 라이브러리에서 불러온 함수와 직접 구현한 함수가 속도차이 10배정도를 보였
juhee-maeng.tistory.com
순열
from itertools import permutations
for i in permutations([1,2,3,4], 2):
print(i, end=" ")
(1, 2) (1, 3) (1, 4) (2, 1) (2, 3) (2, 4) (3, 1) (3, 2) (3, 4) (4, 1) (4, 2) (4, 3)
조합
from itertools import combinations
for i in combinations([1,2,3,4], 2):
print(i, end=" ")
(1, 2) (1, 3) (1, 4) (2, 3) (2, 4) (3, 4)