In Python, is there a good way (programmatically) to get the value of ["win"]["amount"]
from the subset of data where the most recent date exists?
To provide a more concrete example of what I'm asking, I'd like the amount
for win
from April 2, 2018 (2018-04-02
), which would be 199.51
.
This is the source JSON (I convert this to a Python dict
using json.loads
):
{
"numbers": [{
"lose": {
"amount": "122.50"
},
"win": {
"amount": "232.50"
},
"date": "2018-01-08"
}, {
"lose": {
"amount": "233.75"
},
"win": {
"amount": "216.25"
},
"date": "2018-03-05"
}, {
"lose": {
"amount": "123.50"
},
"win": {
"amount": "543.00"
},
"date": "2018-03-12"
}, {
"lose": {
"amount": "213.31"
},
"win": {
"amount": "253.33"
},
"date": "2018-03-19"
}, {
"lose": {
"amount": "217.00"
},
"win": {
"amount": "199.51"
},
"date": "2018-04-02"
}]
}
This seems like a very simple solution is in order, but I cannot quite nail down what that solution is, or if there is a Pythonic way of accomplishing this. I did write some logic to calculate the largest date by putting all of the dates into a list called datelist
and doing a max(datelist)
, but I'm not sure how to relate that back to get ["amount"]["win"]
.