Interactive Computer Science Tutoring

Learn programming concepts interactively

AHA Schools Logo

Python Dictionaries

Master key-value data structures and hashing concepts

Learning ModesInteractive
Choose your learning focus and difficulty level

Difficulty Level

Operation Type

Real-World Data Examples

Current Python DictionarySize: 3
Your dictionary contains 3 key-value pairs
"name""Alice"
string
"age"25
number
"city""NYC"
string
Add Key-Value Pairs
Remove Keys
Access Values
Update Values
Global Actions
Python Code
Live Python dictionary representation with highlighted changes
# Python Dictionary Operations Example
# Initialize dictionary with current key-value pairs
{ = true
"name": "Alice",
"age": 25,
"city": "NYC"
}
# Current state: 3 key-value pairs
# Dictionary length: len(my_dict) = 3
# Key Constraints: Keys must be immutable (strings, numbers, tuples)
# Valid keys: 'name', 42, (1, 2), True
# Invalid keys: ['list'], {'dict': 'value'}
# === BASIC OPERATIONS ===
# Access value by key
# my_dict["name"] returns "Alice"
# my_dict["age"] returns 25
# my_dict["city"] returns "NYC"
# === DICTIONARY METHODS ===
# Get all keys, values, and items
my_dict.keys() # dict_keys(['name', 'age', 'city']) = true
my_dict.values() # dict_values(["Alice", 25, "NYC"]) = true
my_dict.items() # dict_items([(key, value), ...]) = true
# Safe access with default values
my_dict.get("key", "default") # Returns "default" if key not found = true
# === NESTED DICTIONARIES ===
# Multi-level dictionary access
{ = true
"user": {"name":"Alice","age":25},
"settings": {"theme":"dark","notifications":true}
}
# Access nested values
# nested_dict["user"]["name"] returns the name
# nested_dict.get("user", {}).get("age", 0) for safe access
# === PERFORMANCE NOTES ===
# Dictionary lookup is O(1) average case due to hashing
# Much faster than list search which is O(n)
# Display dictionary
print(f"Dictionary: {my_dict}")
print(f"Size: {len(my_dict)} key-value pairs")
History0/5
Recent Python dictionary operations with timestamps

No operations yet

Start by adding or modifying elements

Learning Progress

Dictionary Creation
Key-Value Access
Key Constraints
Completed: 0 / 8