Lazo Lab Sign up

Python Fundamentals / Collections

Lesson 26 of 38

Looping over dictionaries

Use .items() to get key and value together, .keys() for just keys and .values() for just values.

Key points

  • for k, v in d.items()
  • in checks for a key
  • Dictionaries keep insertion order
scores = {"ali": 40, "sara": 55}
for name, pts in scores.items():
    print(name, pts)
Watch a video on thisOpens YouTube search results for “Looping over dictionaries” in a new tab

Quiz · +10 XP

Which method gives both keys and values?

Log in to save progress and earn XP.