def subsets(K):
print([])
for i in K:
print([i])
for j in K:
if j == K[-1] or j == i:
break
print([i,j])
for k in K:
if j == K[-1] or j == k:
break
print([i,j,k])
print(K)
K = [1,2,3,4]
subsets(K)
def subsets(seq):
for k in range(len(seq) + 1):
yield from subsets_k(seq, k)
def subsets_k(seq, k):
if k == 0:
yield []
else:
for i in range(len(seq) - k + 1):
for subset in subsets_k(seq[i+1:], k-1):
yield [seq[i]] + subset
print(list(subsets([1, 2, 3, 4, 5])))