I have a list of lists and I need to find the highest combination of values given some constraints:
for example let's say I have:
lst1 = [['a', 1, 100], ['b', 2, 200], ['c', 1.5, 300]]
lst2 = [['d', 1, 100], ['e', 2, 200], ['f', 1.5, 300]]
lst3 = [['g', 5, 100], ['h', 9, 200], ['i', 11, 500]]
If I wanted to get the combination of 1 selection from each list with the highest sum of the 2nd values and the sum of the third values being under 401.
so a possible combination would be ['a', 'd', 'g'] or ['b', 'd', 'h'].
Is there a library optimized for this or would I need to just do something like:
from itertools import product
combinations = list(product(lst1, lst2, lst3))
outcomes = []
for index, combination in enumerate(combinations):
first_total = 0
second_total = 0
for member in combination:
first_total += member[1]
second_total += member[2]
if second_total <= 400:
outcomes.append((index, first_total,))
[['a', ...], ['d', ...], ['g', ...]]? (One item from each of the three lists, and the sum of the third element of each item has to sum to less than 400, making that the only legal combination?)