Jan-16-2018, 07:30 AM
For me, this is an overuse of generator expressions. When they are not needed, it is better (and it may actually be faster) to write ordinary syntax like so
from itertools import combinations def solve(items): for length in range(1, len(items)): for subset in combinations(items, length): if sum(subset) == 0: print('A solution for set {} is {}'.format(items, subset)) return print('There is no solution for set {}'.format(items)) if __name__ == '__main__': solve({-3, -10, 2, 5, 7, 13})Generator expressions are most useful when you want to create and manipulate 'sequences' of things.