python nested list format, search for values greater than or latest
Below is in which I have data.
a = [{'ID': 319684283, 'ID1': 1025018, 'date': '20180107 17:39:46', 'rate': 9.639e05, 'amount': 410.84392747, 'total': 0.03960124, 'order': 16532584965, 'type': 'A', 'category': 'website'}, {'ID': 319684282, 'ID1': 1025017, 'date': '20180107 17:39:46', 'amount': 24.84386425, 'total': 0.00239445, 'order': 16532584965, 'type': 'phone', 'category': 'exchange'}, {'ID': 319684281, 'ID1': 1125117, 'date': '20180117 17:39:16', 'amount': 14.8138145, 'total': 0.10239445, 'order': 16512581965, 'type': 'phone', 'category': 'exchange'}]
How do I pull record which is latest of these. I tried
for c in a:
print(min(c['date']
It failed as it is not able to traverse all the elements. How do I achieve the below out put, limited values:
d = { 'date': '20180117 17:39:16', 'amount': 14.8138145, 'total': 0.10239445, 'order': 16512581965}
Here d should have only the latest value based on date.
1 answer

you need to iterate through each list and then from dictionary need to get the date to find the minimum date. Once you have find the minimum date you will have your value.
min_date = "22220101 00:00:00" for dict in data_list: date = dict.get("date") if date < min_date: value = dict