Algorithm/Python

Python - 중복 순열, 중복 조합

yxemsy 2022. 2. 4. 11:31

1) 중복 순열 - product

from itertools import product

data = ['a', 'b', 'c']

result = list(product(data, repeat=2)) # 중복을 허용하여 2개를 뽑는 모든 순열
print(result)

 

 

2) 중복 조합 - combinations_with_replacement

from itertools import combinations_with_replacement

data = ['a', 'b', 'c']

result = list(combinations_with_replacement(data, 2)) # 중복을 허용하여 2개를 뽑는 모든 조합
print(result)

 

참고: 이코테 2021 강의 동영상