from itertools import combinations
#nCr combinations(n개의 반복 가능한 객체, 뽑는 경우의 수)
#반복 객체가 리스트 일 경우
print(combinations([1,2,3], 1)) #<itertools.combinations object at 0x1044161d0>
print(combinations([1,2,3], 2)) #<itertools.combinations object at 0x1044161d0>
print(combinations([1,2,3], 3)) #<itertools.combinations object at 0x1044161d0>
#그냥 print하면 보이지 X, list나 tuple형태로 형변환 하면 보임
print(list(combinations([1,2,3], 1))) #[(1,), (2,), (3,)]
print(list(combinations([1,2,3], 2))) #[(1, 2), (1, 3), (2, 3)]
print(list(combinations([1,2,3], 3))) #[(1, 2, 3)]
print(tuple(combinations([1,2,3], 2))) #((1, 2), (1, 3), (2, 3))
for i in combinations([1,2,3], 2):
print(i) #(1, 2)
#(1, 3)
#(2, 3)
#튜플 타입으로 반환
#반복 객체가 문자열이면?
print(list(combinations('himinheeya', 2))) #[('h', 'i'), ('h', 'm'), ('h', 'i'), , ......, ('y', 'a')]
#반복 객체가 튜플이면?
print(list(combinations((1,2,3,7), 2))) #[(1, 2), (1, 3), (1, 7), (2, 3), (2, 7), (3, 7)]