i have a data like this:
js = {"data": [
{'state': 'Florida',
'shortname': 'FL',
'info': {'governor': 'Rick Scott'},
'counties': [{'name': 'Dade', 'population': '12345'},
{'name': 'Broward', 'population': '40000'},
{'name': 'Palm Beach', 'population': '60000'}]},
{'state': 'Ohio',
'shortname': 'OH',
'info': {'governor': 'John Kasich'},
'counties': [{'name': 'Summit', 'population': '1234'},
{'name': 'Cuyahoga', 'population': '1337'}]}]
}
The task is to write a program which will print for every state it's population, so the expected output would be:
Florida 22345
Ohio 2571
I have to use json module in this task, but i don't have an idea how.
I only just know how to access 'state' but idk how to sum the population
for i in js['data']:
print(i['state'], i['counties'][0]['population'] + i['counties'][1]['population']... etc but summing up the population manually is no the proper way i guess..)