Dict Items
Predict Output Medium
Question
What does this code print?
Code
d = {"x": 1, "y": 2}
print(len(d.items()))
Hint
items returns key-value pairs.
Explanation
d.items() returns dict_items([("x", 1), ("y", 2)]). len() counts 2 key-value pairs. Used for iteration: for key, value in d.items().
Related Resources
Related Lessons
- Dictionaries
Learn Python dictionaries.
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.