Data Structures

Dictionaries

A dictionary stores data as key-value pairs.

Creating Dictionaries

person = {
    "name": "Alice",
    "age": 25,
    "city": "New York"
}

Accessing Values

person["name"]      # "Alice"
person.get("age")   # 25
person.get("job", "Unknown")  # "Unknown" (default)

Modifying Dictionaries

person["age"] = 26           # Update value
person["job"] = "Developer"  # Add new key
del person["city"]           # Remove key

Looping

# Keys
for key in person:
    print(key)

# Values
for value in person.values():
    print(value)

# Both
for key, value in person.items():
    print(f"{key}: {value}")
Visualizer
student3 rows
keyvalue
nameAlice
gradeA+
subjects[Math, Science]

Interactive Visualization

python
Loading...
Output
Run execution to see output...