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

I am a bit confused

The question is kind of confusing because

student = {'name': 'Craig', 'major': 'Computer Science', 'credits': 36}

for key in student.():

I don't understand what I would put in the blank because if you ant just the key you would just do

for item in student:

and I don't see where we would use a method in this question but it is asking for a method. Thanks for any help you can offer. :)

1 Answer

Scott Bailey
Scott Bailey
13,177 Points

Because it's a dictionary the information is stored in 'key': 'value' pairs. So the key would be 'name' and the value 'Craig' (for example).

The question your on is asking for the key - so student.keys() is what their looking for.

It's true you can cycle through it like you mentioned - I found a good post on stackoverflow which might shed a bit more light on the matter here

In the quiz i think they just want you to be aware that you can use .keys() in this way. There may be more to it, maybe it's best practice to or something like that.