How to find what values of a list sum to a specified value
问题 I am programming a knapsack encryption algorithm. I am new to Python programming. I have a list and an integer value I have determined. I want to find what elements in my list will sum up to my integer value. I can get it running for two elements or less but I can not run it for more than two elements. Assume: privkey = [2,3,6,13,27,52] cipher = 9 My current function can run the scenario above: searchList = [] for i, number in enumerate(privkey[:-1]): complementary = cipher - number if