Fill: Dict Items Iteration
Fill in the Blank Medium
Question
Fill in the blank to iterate over key-value pairs.
Code
d = {"a": 1, "b": 2}
for k, v in d.___():
print(k, v)
Hint
The method that returns key-value pairs is...
Explanation
items() returns a view of the dictionary's key-value pairs as tuples. The for loop unpacks each tuple into k and v. Output: a 1, then b 2.
Related Resources
Related Lessons
- Dictionaries
Iterating dicts.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.