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

How do i complete the code so it iterates over only the values in the student dictionary.

I want to fill in the missing word of the following code:

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

for val in student.____(): print(val)

2 Answers

Steven Parker
Steven Parker
231,275 Points

Believe it or not, the name of the dictionary method that returns just the values is ... "values".   :wink:

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,722 Points

Often, you will want to know the key and value at the same time, so it's convenient to use a programming pattern that can serve double duty (e.g. the student.items() iterator).

student={'name': 'Craig', 'major': 'Computer Science', 'credits': 36}
# print just values
for value in student.values():
   print(value)

# print just the keys
for key in student.keys():
    print(key)

# print key and value
for key, value in student.items():
    print(key, value)

thank you Jeff