Python Introducing Dictionaries Iterating and Packing with Dictionaries Recap of Iterating and Packing with Dictionaries

Chris Hummel
Chris Hummel
12,477 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 65,296 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!