Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,275 Points

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

i dont remember learing the key method

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