I've spent the last hour doing some data entry and have hit a brick wall in Python now.
Basically I have a set of data in JSON, where I want to sum the values from field price
to add up to a certain value (14.0 in my case). The final result should maximise the sum of the return
field. Here's an example of my dataset (there are more teams and fields):
[
{ "team": "England", "price": 7.0, "return": 2.21 },
{ "team": "Belgium", "price": 7.0, "return": 2.27 },
{ "team": "Spain", "price": 6.0, "return": 2.14 },
{ "team": "Slovakia", "price": 1.0, "return": 0.97 }
]
So in this case, there are 3 possible answers:
a) England, Belgium (4.48)
b) England, Spain, Slovakia (5.28)
c) Belgium, Spain, Slovakia (5.38)
With c) being the optimum because it has the biggest sum of return
(5.38). I would like to use Python to implement the solution.
I've had a look at this question, but can't seem to figure out how to implement it in my case: Finding all possible combinations of numbers to reach a given sum