I need help with looping through the values of a dictionary.
The output only takes the first row of the dictionary instead of the entire dictionary. For example, Year 1800 should have different values for each borough. What's wrong with my code?
def combine_dict(year_dict, headers): borough={} i=0 for x in year_dict: while i<len(headers)-1: borough[headers[i+1]]=year_dict[x][i] i+=1 for y in nums: nums[y]=borough return(nums) pop_dict= combine_dict(pop_dict, pop_headers) pprint(pop_dict)
The output only takes the first row of the dictionary instead of the entire dictionary. For example, Year 1800 should have different values for each borough. What's wrong with my code?
Output:{'1790': {'Bronx': '1781', 'Brooklyn': '4549', 'Manhattan': '33131', 'Queens': '6159', 'Staten Island': '3827'},
'1800': {'Bronx': '1781', 'Brooklyn': '4549', 'Manhattan': '33131', 'Queens': '6159', 'Staten Island': '3827'},
buran write May-21-2021, 04:50 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.