I've been trying to convert a list of dictionaries into a single dictionary in such a way where each key is <city>, <state> and each value is <county>.
In short I have a list that looks like this.
[{'city': 'Normal',
'county': 'Madison County',
'state': 'Alabama'},
{'city': 'Birmingham',
'county': 'Jefferson County',
'state': 'Alabama'},
{'city': 'Montgomery',
'county': 'Montgomery County',
'state': 'Alabama'}]
And I would like to change it into something like this
{'Normal, Alabama': 'Madison County',
'Birmingham, Alabama': 'Jefferson County',
'Montgomery, Alabama': 'Montgomery County'}
I tried dictionary comprehensions but can't seem to add two different keys at once.
So I know the code below will give me a dictionary with cities and counties for key value pairs
new_dict = {x['city']: x['county'] for x in counties}
However, how do I add two different keys? Something like new_dict = {x['city','state']: x['county'] for x in counties} won't work.