Last active
February 15, 2017 18:38
-
-
Save joetechem/97d423651ed2080c8c3941f2f084df92 to your computer and use it in GitHub Desktop.
quick view at nesting: Python list in a dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# example from Python Crash Course by Eric Matthes | |
# store info about a pizza being ordered | |
# list in a dictionary | |
pizza = { | |
'crust':'thick', | |
'toppings': ['mushrooms', 'pepperoni', 'extra cheese'], | |
} | |
# summarize the order: | |
print("You ordered a " + pizza['crust'] + "-crust pizza " + | |
"with the following toppings:") | |
for topping in pizza['toppings']: | |
print("\t" + topping) | |
# Let's look at another example... | |
# From our look at the similar objects dictionary | |
# where we look at a poll taken from a population for favorite programming languages | |
favorite_languages = { | |
'jen': ['python', 'ruby'], | |
'sarah': ['c'], | |
'edward': ['ruby', 'go'], | |
'phil': ['python', 'haskell'], | |
} | |
for name, languages in favorite_languages.items(): | |
print("\n" + name.title() + "'s favorite languages are:") | |
for language in languages: | |
print("\t" + languages.title()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment