from itertools import combinations
lis = [1, 2, 3, 4]for i in range(1, len(lis) + 1):
#range will return the values 1,2,3,4 in this loop
print (list(combinations(lis, i)),'\n')
print (list(combinations([1, 2, 3, 4], 3)))
===================== RESTART: F:/Python_APSC/b038-2.py =====================
[(1,), (2,), (3,), (4,)]
[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
[(1, 2, 3, 4)]
[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
>>>
沒有留言:
張貼留言