Concept
What is a Dictionary: Key-Value Magic
Dictionaries store data in `key: value` pairs using curly braces `{}`. Lookups by key are lightning fast ($O(1)$ hash maps).
python
hero = {"name": "Zelda", "hp": 100}
print(hero["name"]) # Zelda
print(hero["hp"]) # 100
# 78. What is a Dictionary: Key-Value Magic Dictionaries store data in `key: value` pairs using curly braces `{}`. Lookups by key are lightning fast ($O(1)$ hash maps): ```python hero = {"name": "Zelda", "hp": 100} print(hero["name"]) # Zelda print(hero["hp"]) # 100 ``` Unlike lists where you must remember index numbers (`hero[0]`), dictionaries let you access data using descriptive human words (`hero["hp"]`).
Checkpoint
How do dictionaries find values so quickly?
Practice
Create a dictionary named `user` with key `"role"` set to `"admin"`. Print `user["role"]`.
01
Tap code blocks below to assemble
Available Blocks