How do you read through a file to get specific key value pairs with 1 key, and 2 values that are in a dictionary? [closed]
The first parameter is a dictionary representing data for a city and the second parameter is a data file that is open for reading. This function should modify the dictionary so that it contains the data in the file.
If a city with data in the file is already in the dictionary then its data should be updated. Otherwise it should be added to the dictionary with its data.
After this function is called, the dictionary should contain key/value pairs whose keys are the names of every city in the data file, and whose values are dictionaries which contain at least the population and economics_situation for those cities.
I'm just trying to figure how to even start with this? Can anybody give me a clue, or a first step on an approach?
We want our dict to look something like this: This is assuming if its an empty dictionary
'''
{'Brampton': {'#': 1, 'population': [703, 38907, 6789, 8769, 9087, 9087]},
'Pickering': {'#': 2, 'population': [789, 10987, 4678, 3980, 9087, 4789]},
'Toronto': {'#': 3, 'population': [220, 6789, 1678, 1098, 1098, 2908]},
'Oshawa': {'#': 4, 'population': [201, 2900, 8000, 3229, 2809, 2789]},
'Ottawa': {'#': 5, 'population': [100, 290, 5000, 2842, 948, 5677]}}
'''
Our file would have be (in row 1):
Column index Description
HT_ID_COL An ID that uniquely identifies each city.
HT_NBH_NAME_COL The name of the city. City names are unique.
HT_20_44_COL The number of people aged 20 to 44 with hypertension in the city.
NBH_20_44_COL The total number of people aged 20 to 44 in the city.
HT_45_64_COL The number of people aged 45 to 64 with hypertension in the city.
NBH_45_64_COL The total number of people aged 45 to 64 in the city.
HT_65_UP_COL The number of people aged 65 and older with hypertension in the city
Comments
Post a Comment