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

Chris Hummel
Chris Hummel
13,189 Points

Where is the syntax shown for this?

I've rewatched the videos several times, and I'm not seeing where the syntax for this was dicussed: Complete the code so it will iterate over only the keys in the student dictionary.

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

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

I tried items, but it says it's wrong. What am I missing here?

2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 67,464 Points

Hey Chris Hummel, the .keys() method was discussed in the previous segment video

Introducing Dictionaries —> Accessing Keys and Values around 2:45.

Post back if you need more help. Good luck!!!

Hi Chris!

I couldn't find a specific place where they really explained the breakdown of quiz questions two and three, but it seemed logical to me that if student.items() gave the key-value pairs, that student.keys() would give you just the keys and student.values() would give you just the values.

I tried both and they passed.

This covers the whole topic pretty well, though:


I hope that helps.

Stay safe and happy coding!