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

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

# 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!!!