Python Nesting - A dictionary of dictionaries
You can store a dictionary inside another dictionary. In this case each value associated with a key is itself a dictionary.
#Storing dictionaries in a dictionary users = { 'aeinstein':{ 'first': 'albert', 'last': 'einstein', 'location': 'princeton', }, 'mcurie': { 'first': 'marie', 'last': 'curie', 'location': 'paris', }, } for username, user_dict in users.items(): print("\nUsername: " + username) full_name = user_dict['first'] + " " full_name += user_dict['last'] location = user_dict['location'] print("\tFull name: " + full_name.title()) print("\tLocation: " + location.title())
No comments:
Post a Comment