intermediate20 min
Dictionaries
Key-value pairs for structured data
What are Dictionaries?
A dictionary stores data as key-value pairs. Think of it like a real dictionary — you look up a word (key) to find its definition (value).
Creating Dictionaries
Output
Run your code to see output here
Working with Dictionaries
Dictionary Operations
Output
Run your code to see output here
Useful Dictionary Methods
Dictionary Methods
Output
Run your code to see output here
Nested Data Structures
Dictionaries and lists can be combined:
Nested Structures
Output
Run your code to see output here
Check Your Understanding
How do you access the value for key 'name' in dict `d`?
Exercise
Create a dictionary called `book` with keys: 'title', 'author', and 'year'. Print each value on a separate line.
Python will load on first run