You can type text or code! These blocks execute things.
# Press SHIFT + ENTER to run this cell!
print("It Worked!")
We want to figure out where we want to go for dinner tonight. And we are craving hamburgers :).
This leads us to a first data structure: a string
In the cell below, create and print a string called "mcdonalds"
restaurant_1 =
print(restaurant)
Use the capitalize()
method to capitalize the contents of our restaurant
variable. Print the variable again to see our changes!
restaurant_1 =
print(restaurant)
We want to collect our data. A list is an ordered collection. You can use square brackets to create a list. You can use
- the original strings
- the stored variables
restaurant_2 =
restaurants =
same_restaurants =
Note that these two are exactly the same! You can test for this:
restaurants == same_restaurants
What if we want to access information inside restaurants
or same_restaurants
?
What if you want to add a burger restaurant to your list? Append 'Shake Shack'
to restaurants
# Append "Shake Shack" to restaurants!
print(restaurants)
Maybe we want to save attributes for our restaurants? Lists are not very useful here.
mcdonalds = {'name':'mcdonalds', 'address': "85 broad street"}
Why not a list? Dictionaries have keys
and values
.
mcdonalds.keys()
mcdonalds.values()
You can wrap this into a list
list(mcdonalds.values())
Create two more restaurant dictionaries for the following restaurants:
Restaurant | Address |
---|---|
Burger King | 1313 Broadway |
Shake Shack | 691 8th Ave |
Now use the correct key to access the address for Shake Shack:
Now, we'll set up for the final programming challenge of this lesson.
First, create a list containing the restaurant dictionaries we made above.
list_of_dictionaries =
In the cell below, iterate through our list of dictionaries, and print out "{Restaurant Name} is located at {Restaurant Address}!" for each restaurant.
Your output should be:
"mcdonalds is located at 85 broad street!"
"Burger King is located at 1313 broadway!"
"Shake Shack is located at 691 8th Ave!"