-
퍼뮤테이션(permutation): 순열 또는 치환
permutations(n, r).
입력된 n개를 이용하여 조합이 반복되지 않게(서로 다른 순서로 반복은 가능) r개씩 짝을 지어 반환. 반환되는 방식은 iterable이다. 조합에 순서를 구분하여 다른 순서는 다른 조합으로 인식.>>> import itertools >>> list(itertools.permutations([11,22,33,44],1)) [(11,), (22,), (33,), (44,)] >>> list(itertools.permutations([11,22,33,44],2)) [(11, 22), (11, 33), (11, 44), (22, 11), (22, 33), (22, 44), (33, 11), (33, 22), (33, 44), (44, 11), (44, 22), (44, 33)] >>> list(itertools.permutations([11,22,33,44],3)) [(11, 22, 33), (11, 22, 44), (11, 33, 22), (11, 33, 44), (11, 44, 22), (11, 44, 33), (22, 11, 33), (22, 11, 44), (22, 33, 11), (22, 33, 44), (22, 44, 11), (22, 44, 33), (33, 11, 22), (33, 11, 44), (33, 22, 11), (33, 22, 44), (33, 44, 11), ( 33, 44, 22), (44, 11, 22), (44, 11, 33), (44, 22, 11), (44, 22, 33), (44, 33, 11 ), (44, 33, 22)] >>> list(itertools.permutations([11,22,33,44],4)) [(11, 22, 33, 44), (11, 22, 44, 33), (11, 33, 22, 44), (11, 33, 44, 22), (11, 44 , 22, 33), (11, 44, 33, 22), (22, 11, 33, 44), (22, 11, 44, 33), (22, 33, 11, 44 ), (22, 33, 44, 11), (22, 44, 11, 33), (22, 44, 33, 11), (33, 11, 22, 44), (33, 11, 44, 22), (33, 22, 11, 44), (33, 22, 44, 11), (33, 44, 11, 22), (33, 44, 22, 11), (44, 11, 22, 33), (44, 11, 33, 22), (44, 22, 11, 33), (44, 22, 33, 11), (44 , 33, 11, 22), (44, 33, 22, 11)] >>> list(itertools.permutations([11,22,33,44],5)) [] >>>
순서가 다른 같은 값 조합을 피하려면 combination함수 참고: 2020/09/06 - Python - combination 클래스 함수
'Python' 카테고리의 다른 글
Python - iterable 유형 (0) 2020.09.06 Python - product (0) 2020.09.06 Python - deque (0) 2020.09.06 Python - combination 클래스 함수 (0) 2020.09.06 Python - tuple() 클래스 함수 (0) 2020.09.06 Python - dict() 클래스 함수 (0) 2020.09.06 Python - reduce 함수 (0) 2020.09.06 Python - sorted 함수 (0) 2020.09.05