Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,878 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!