Reputation: 1037
I am creating a Python3 dictionary:
parents = {
'parent_0': {
'f_name': 'john',
'l_name': 'doe',
'location': 'New York, NY',
'birth_month': 'september',
'nationality': 'france',
},
'parent_1': {
'f_name': 'jane',
'l_name': '',
'location': '',
'birth_month': 'may',
'nationality': ''
},
}
How can parent_1 inherit the key values for l_name, location and nationality from parent_0?
Upvotes: 0
Views: 102
Reputation: 8996
for key in parents['parent_1'].keys:
if parents['parent_1'] == '':
parents['parent_1'][key] = parents['parent_0'][key]
Upvotes: 1
Reputation: 5273
for key, value in parents['parent_1'].items():
if not value:
parents['parent_1'][key] = parents['parent_0'][key]
Upvotes: 2