Skip to content

Instantly share code, notes, and snippets.

@joetechem
Last active February 15, 2017 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joetechem/97d423651ed2080c8c3941f2f084df92 to your computer and use it in GitHub Desktop.
Save joetechem/97d423651ed2080c8c3941f2f084df92 to your computer and use it in GitHub Desktop.
quick view at nesting: Python list in a dictionary
# 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