Dictionaries - Meaning Over Position
13 / 15

What Is a Dictionary?

"A collection of key-value pairs. Unlike lists where numeric position matters, dictionaries use meaningful names (keys) to unlock values directly."

Lists vs Dictionaries

LIST (Position-Based)
["John", 25, "Engineer"]
[0] → "John"
[1] → 25
[2] → "Engineer"
Access by index number
Ordered sequence
Wait—what does [1] represent?
DICTIONARY (Key-Based)
{"name": "John", "age": 25, "job": "Engineer"}
["name"] → "John"
["age"] → 25
["job"] → "Engineer"
Access by meaningful key
Instant key → value lookup
Self-documenting code!
Key Difference: Lists use numbers (indices), while dictionaries use meaningful labels (keys). Dictionaries are self-documenting—the key tells you immediately what the value means.

Interactive Dictionary Builder & Key Lookup

Interactive Key Lookup Bar (click to test person[key] live):
Add or click key-value pairs to inspect dictionary operations!
CHEAT SHEET Dictionary Operations (Access, Update, in, .keys(), .values()) + Explore
# Creating a dictionary
person = {
    "name": "Alice",
    "age": 30,
    "job": "Engineer"
}

# Accessing values by key
name = person["name"]        # "Alice"
age = person["age"]          # 30

# Adding or updating values
person["city"] = "Boston"    # Adds new key-value pair
person["age"] = 31           # Updates existing key

# Checking if a key exists before accessing
has_job = "job" in person    # True

# Inspecting all keys or values
keys = person.keys()         # dict_keys(["name", "age", "job", "city"])
values = person.values()     # dict_values(["Alice", 31, "Engineer", "Boston"])
CODE EXAMPLES When to Use Dictionaries & Student Gradebook Example + Explore
  • Named records: When attributes have clear labels ("name", "score", "email")
  • Lookup tables: Mapping one thing directly to another (word → definition, item → price)
  • Configuration & state: Storing settings or player inventory by name
  • Structured data: Working with JSON responses and API payloads
# Student grades - dictionary is crystal clear
grades = {
    "Alice": 95,
    "Bob": 87,
    "Charlie": 92
}

# Look up directly by student name
alice_grade = grades["Alice"]  # 95
Forget-Me-Nots Encouragement
Forget-Me-Nots Collected! (14 / 16)
You've mastered pairing meaningful keys with values. Next up: solving self-similar problems with Recursion!
Lists look up items by position, while dictionaries look them up by key. Pairing values with clear keys makes data self-explanatory.
Wizard Guide