I have I have such a datastructure:
dataset = [{'country': 'Afghanistan',
'continent': 'Asia',
'1990': 500,
'1991': 500,
'1992': 500,
'1993': 1000},
{'country': 'Albania',
'continent': 'Europe',
'1990': 100,
'1991': 100,
'1992': 100,
'1993': 100}
{'country': 'Algeria',
'continent': 'Africa',
'1990': 500,
'1991': 500,
'1992': 1000,
'1993': 1000
}]
I need to find max value in year 1991 and create a dictionary with keys - country, where this maximum value was, the year we are looking for (1991) and the maximum value found.
I was thinking of making it that way, but it didn't work.
new_dict = {}
str_year = str(year)
for dict_ in dataset:
for key, values in dict_.items():
max_val = max(dict_, key=lambda x:x[str_year])
new_dict = {'country' : dict_['country'], 'year': year, 'cases': max_val}
return new_dict
How can I do this?