[Solved] Print all combinations of list that sum to a number [closed]


You were pretty close:

import itertools

l = [1,2,3,4,5,6]
ts = 8

def psl(l, ts):
    for i in range(len(l)):
        for c in itertools.combinations(l, i):
            if sum(c) == ts:
                print list(c)

psl(l, ts)

solved Print all combinations of list that sum to a number [closed]