Process Overview
A dictionary is a way to store data using pairs of keys and values. Each key is unique and points to a value, like a label on a box telling you what is inside. This flowchart shows how to look up a value by its key in a dictionary.
Jump into concepts and practice - no test required
A dictionary is a way to store data using pairs of keys and values. Each key is unique and points to a value, like a label on a box telling you what is inside. This flowchart shows how to look up a value by its key in a dictionary.
Dictionary Memory Layout: +-------------------+ | Key | Value | +-------------------+ | 'apple' | 3 | +-------------------+ | 'banana'| 5 | +-------------------+ Lookup Process: Key: 'banana' --> Find in keys --> Return 5
{'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.