Example:
request = requests.get('https://api.amountofsomething.com')
amount = request.json()['amount']
This request returns values like these:
[{"amount": 0.1}, {"amount": 2},{"amount": 145},{"amount": 5.84}]
I need to make sums, without patterns, of different index values. I have done so, and it worked, but for large amounts of data the code gets very large.
amount0 = amount[0]['amount']
amount1 = amount[1]['amount']
amount2 = amount[2]['amount']
sum0 = amount0 + amount2
> > > sum0 = 0.1 + 145
...
I tried different ways to manipulate this data to generate fewer codes.
sum0 = amount [0+2]['amount']
sum1 = amount [[0] + [2]]['amount']
sum2 = amount [0]['amount'] + amount [2]['amount']
None of these options worked, can anyone give me a hand?