This is Key - done, but need explanation


#1

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/2?curriculum_id=4f89dab3d788890003000096

The code is fine and I passed the exercise, but! How does it know that I am looking for the values of the keys? I used "definition" if for loop.

Is it because it is in the brackets? Just to confirm - the thing I put into brackets is the value?

webster = {
	"Aardvark" : "A star of a popular children's cartoon show.",
    "Baa" : "The sound a goat makes.",
    "Carpet": "Goes on the floor.",
    "Dab": "A small amount."
}

# Add your code below!
for dictionary in webster:
    print webster[dictionary]

#2

here you declare your for loop:

for dictionary in webster:

dictionary is your iterator, it will contain your keys (aardvak, baa, carpet) so you can use dictionary as key (between square brackets) to get the values


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.