Python Nesting - A dictionary of dictionaries - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Python Nesting - A dictionary of dictionaries - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Friday, December 7, 2018

Python Nesting - A dictionary of dictionaries

Python Nesting - A dictionary of dictionaries







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())

Screenshot 

python nesting

 

No comments:

Post a Comment

Post Top Ad