I have a dictionary in python like this:
x = {country:{city:population}:……}
and I want to create a new dictionary like y = {country:cities_population}, where cities_population adds all the population in every city in every country and I really don’t know how to do it.
I tried this:
for country in x:
for city, population in x[country].iteritems():
if not country in y:
y[country] = {}
y[country] += population
I check for a dictionary with only one key and one value but I don’t understand how to manage a three items dictionary… help me please!!!! 🙂
Well, how about: