Feb-06-2021, 12:04 PM
(This post was last modified: Feb-06-2021, 12:57 PM by tristanfermat.)
I have this one but It doesn't work as I wanted.
import itertools import functools test_matrix = [] stuff = [100,500,300,200] for L in range(0, len(stuff)+1): for subset in itertools.combinations(stuff, L): test_matrix.append(subset) while True: res = functools.reduce(lambda i, j: i if 4000 < sum(j) else j, test_matrix) test_matrix.remove(res) a = sum(int(b) for b in res) print (a) print ("Maximum sum sublist is : " + str(res))