git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

itertools query


Hi all,

I have written a small program to generate all the combinations of a and b
of the array. I want (6,7) tuple also included. Can anybody suggest what
change I should make to get 6,7 included in my output? Any suggestions


 Output:
[(5,), (6,), (5, 6), (7,), (8,), (7, 8)]

from itertools import chain, combinations

a = [5,6]
b = [7,8]
ar=[]
br=[]

def all_subsets(ss):
    return chain(*map(lambda x: combinations(ss, x), range(1, len(ss)+1)))

for subset in all_subsets(a):
    print(subset)
    ar.append(subset)

for subset in all_subsets(b):
    print(subset)
    br.append(subset)

fr=ar+br
print(fr)