In the process of self-learning Python. On the topic of nested dictionaries. I am unable to accomplish this example:
Extract the value associated with the key color and assign it to the variable color. Do not hard code this.
info = {'personal_data':
{'name': 'Lauren',
'age': 20,
'major': 'Information Science',
'physical_features':
{'color': {'eye': 'blue',
'hair': 'brown'},
'height': "5'8"}
},
'other':
{'favorite_colors': ['purple', 'green', 'blue'],
'interested_in': ['social media', 'intellectual property', 'copyright', 'music',
'books']
}
}
I’ve been able to extract from an un-nested dictionary, getting into the second and third layer is proving beyond my understanding. I neglected to keep every solution I attempted however this is a sample of my lines of thought.
Keyerror 'color'
c = []
for col in info:
c.append(info[col]['color'])
Keyerror ‘color
for c in info.values():
print(c['color'])
TypeError: string indices must be integers
print(info['personal_data']['name']['color'])
I apologize if the syntax of this post is off. I'm learning the etiquette.