itertools.combinationsfrom itertools import combinations
combinations(iterable, r)
iterable: 조합을 생성할 대상인 iterable 객체 (리스트, 문자열 등)r: 선택할 요소의 개수 (조합의 크기)from itertools import combinations
nums = [1, 2, 3, 4]
comb = combinations(nums, 3)
for c in comb:
print(c)
(1, 2, 3)
(1, 2, 4)
(1, 3, 4)
(2, 3, 4)
itertools.combinations를 사용하면 가능한 모든 조합을 쉽게 생성할 수 있어, 데이터 분석이나 알고리즘 문제에서 매우 유용하게 활용할 수 있어 보인다!