How might one store the path to a value in a dict
of dict
s? For instance, we can easily store the path to the name
value in a variable name_field
:
person = {}
person['name'] = 'Jeff Atwood'
person['address'] = {}
person['address']['street'] = 'Main Street'
person['address']['zip'] = '12345'
person['address']['city'] = 'Miami'
# Get name
name_field = 'name'
print( person[name_field] )
How might the path to the city
value be stored?
# Get city
city_field = ['address', 'city']
print( person[city_field] ) // Obviously won't work!