Introduction
Imagine you have a big box of labeled jars, and you want to find the contents quickly without opening each jar. This is the problem dictionaries solve in computing: storing and finding information fast using labels called keys.
Jump into concepts and practice - no test required
Think of a dictionary like a phone book where each person's name is a key and their phone number is the value. When you want to call someone, you look up their name and find their number quickly.
┌───────────────┐
│ Dictionary │
├───────────────┤
│ Key │ Value │
├───────┼───────┤
│ Name │ Alice │
│ Age │ 30 │
│ City │ Paris │
└───────┴───────┘{'name': 'Alice', 'age': 30} uses correct syntax with colons and curly braces; others use wrong symbols or brackets.person = {'name': 'Bob', 'age': 25}
print(person['age'])person['age'] retrieves the value linked to key 'age'.print(person['age']) outputs 25.data = {'x': 10, 'y': 20, 'x': 30}
print(data['x'])data['x'] shows 30, the last assigned value, overwriting 10.students = [('Anna', 85), ('Ben', 92), ('Cara', 85), ('Dan', 92)]{name: score for name, score in students} correctly maps name: score. {score: name for name, score in students} reverses keys and values, causing score keys to overwrite. Options C and D add conditions changing values or keys incorrectly.