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

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
216,768 Points

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

Jeff Muday
Jeff Muday
Treehouse Moderator 27,545 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 just the keys
for key in student.keys():

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

thank you Jeff