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

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
MOD
Chris Freeman
Treehouse Moderator 68,457 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:

https://realpython.com/iterate-through-dictionary-python/

I hope that helps.

Stay safe and happy coding!