i trying add tuples inside subset together.
so far have:
list(itertools.combinations(((1, 'aa'), (2, 'bb'), (3, 'cc'), (4, 'dd'), (5, 'ee'), (6, 'ff'), (7, 'gg'), (8, 'hh')), 6))
which produces:
((1, 'aa'), (2, 'bb'), (5, 'ee'), (6, 'ff'), (7, 'gg'), (8, 'hh')), ((1, 'aa'), (3, 'cc'), (4, 'dd'), (5, 'ee'), (6, 'ff'), (7, 'gg')),
but want add numerical values , nonnumerical values such as:
(29, 'aa'+'bb'+'ee'+'ff'+'gg'+'hh')
i want sort them in ascending order maximum. took me 1 line in mathematica driving me crazy in python.
you can in 1 (and bit) line in python if you're comfortable list comprehensions/generator expressions:
combs = list(itertools.combinations( ((1, 'aa'), (2, 'bb'), (3, 'cc'), (4, 'dd'), (5, 'ee'), (6, 'ff'), (7, 'gg'), (8, 'hh')), 6 )) sums = [ (sum(n n, text in comb), ''.join(text n, text in comb)) comb in combs ] # sort number first, text, default sorted(sums) out[8]: [(21, 'aabbccddeeff'), (22, 'aabbccddeegg'), (23, 'aabbccddeehh'), (23, 'aabbccddffgg'), (24, 'aabbccddffhh'), (24, 'aabbcceeffgg'), (25, 'aabbccddgghh'), (25, 'aabbcceeffhh'), # etc.