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

Luke Tate
PLUS
Luke Tate
Courses Plus Student 2,244 Points

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

imo
imo
7,893 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
Luke Tate
Luke Tate
Courses Plus Student 2,244 Points

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