Python Nesting-Lists in a dictionary - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Python Nesting-Lists in a dictionary - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Friday, December 7, 2018

Python Nesting-Lists in a dictionary

Python Nesting-Lists in a dictionary





Nesting-Lists in a dictionary

Storing a list inside a dictionary alows you to associate more thanone value with each key.

#storing lists in a dictionary
#store multiple languages for each person.
fav_languages = {
 'jen': ['python', 'ruby'],
 'sarah': ['c'],
 'edward': ['ruby', 'go'],
 'phil': ['python', 'haskell'],
}
# Show all responses for each person.
for name, langs in fav_languages.items():
 print(name + ":")
 for lang in langs:
  print("-" + lang)

Screenshot 

nesting list

 

No comments:

Post a Comment

Post Top Ad