5.1.9 Iterating Key-Value Pairs: items()

Unit: Unit 5: Dictionaries and Sets • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Iterate over key-value pairs using items() and tuple unpacking
student_grades = {
    "Ada": 98,
    "Alan": 95,
    "Grace": 99,
    "Linus": 92
}

print("Student Grade Report:")
# Unpack each (key, value) tuple directly in the for loop
for student, score in student_grades.items():
    print(f"- {student}: {score}%")
Open in Live Interactive Python Sandbox →