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

Why doesn't 'items' work, in the for loop when accessing strictly, either key or value?

I'm taking the last quiz, so I'm given a couple of fill in the blanks that deal with filling out for loops of either finding the key, or value. For example:student={"name":"Craig",etc} for key in student.__(): print(key). Whenever I type "items", "key",and "value" on both questions, I always get an error. Plus, no tutorial, on packing or iteration of dictionaries dealt with only asking for only one or the other(key, or value).

1 Answer

7,897 Points
# They asked 3 fill in for loop questions
# Complete this code so that it will iterate over all the key:value pairs in the student dictionary.
# Here they want it to iterate over all key:value pairs, in this case you would use ".items()"

#Complete the code so it will iterate over only the keys in the student dictionary.
# Here they asked only for the keys in the dictionary, you would do this using the ".keys()"

#Complete the code so it iterates over only the values in the student dictionary.
# And for the last they need only the values, you would use ".values()"

# ps. just remember this
# **kwargs packs dictionary
# *args packs tuple

I get it now! The key, and value should be used in each of their plural state. Thanks!!!