I have a nested dictionary of the form:
{'2015-01-01': {'time': '8', 'capacity': '5'},
'2015-01-02': {'time': '8', 'capacity': '7'},
'2015-01-03': {'time': '8', 'capacity': '8'} etc}
The dictionary is created from a csv file using dictreader. What I would like to be able to do is return the maximum value of capacity. So in this case 8.
I can use:
for k,v in input_dict.items():
if temp_max < int(v['capacity']):
temp_max = int(v['capacity'])
which works but I wondered if there was a neater method? I've searched and found methods to extract the top level key associated with the maximum value which is of course not what I need. See below:
max(input_dict, key=lambda v: input_dict[v]['capacity'])
which would return '2015-01-03', So I imagine there is a simple mod to the above one liner that will give me what I need but is has me stumped!
Any ideas?