Python Introducing Dictionaries Iterating and Packing with Dictionaries Recap of Iterating and Packing with Dictionaries

Confusion on For Loop in Python in Intro to Dictionaries

I have rewatched the videos on this one and am not sure why the items word is not the fill in the blank for all of the quiz.

It feels like they would be calling the items() method on the loop to get the iteration of the keys.

Not sure what I am doing wrong?

Here is the code:

student = {'name': 'Craig', 'foo': 'bar'}

for key in student. ____(): print(key)

2 Answers

Steven Parker
Steven Parker
207,972 Points

The "items" method returns both the keys and the values. If you only want the keys, you can use the "keys" method.

Blue DiamondXD
Blue DiamondXD
5,369 Points

i dont remember learing the key method

Omigosh! Can't believe I missed that. Thank you SO MUCH for your speedy response, Steven!