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

I am a bit confused

The question is kind of confusing because

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

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

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:
     print(item)

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,190 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.