쉬엄쉬엄블로그

Python permutations 본문

코딩

Python permutations

쉬엄쉬엄블로그 2022. 4. 11. 22:32
728x90

순열을 구할 수 있는 함수 permutations

from itertools import permutations

 

a = [1, 2, 3]

 

permutations(a, 2)

=> a 리스트의 원소들 중 2개를 추출하여 만들 수 있는 모든 순서쌍을 객체로 반환

list(permutations(a, 2))

=> [(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]

 

 

참고

조합을 구할 수 있는 함수 combinations

 

list(combinations(a, 2))

=> [(1, 2), (1, 3), (2, 3)]

 

 

- 순열은 순서를 고려함

- 조합은 순서를 고려하지 않음

'코딩' 카테고리의 다른 글

Python set  (0) 2022.04.14
Python collections  (0) 2022.04.14
Python PriorityQueue  (0) 2022.04.09
Python any(), all()  (0) 2022.04.02
Python deque  (0) 2022.03.29
Comments