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 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)
No comments:
Post a Comment