[concept]Python Basics
Dictionaries
# theory
A dict is a hashmap. Keys to values:
person = {"name": "Alice", "age": 30, "city": "Boston"}
Access with brackets or .get(). The first raises KeyError on missing keys; .get() returns None or a default:
person["name"] # "Alice"
person.get("job") # None
person.get("job", "unknown") # "unknown"
Add, modify, delete:
person["job"] = "engineer"
person["age"] = 31
del person["city"]
Useful methods: .keys(), .values(), .items() (iterates pairs).
Nest freely:
employees = {
"emp001": {"name": "Alice", "dept": "Engineering"},
"emp002": {"name": "Bob", "dept": "Marketing"},
}
employees["emp001"]["name"] # "Alice"
Reach for a dict whenever you'd describe the relationship as "look this up by name". Counting occurrences, caching results, indexing rows by id.
# examples [3]
Creating and accessing dictionary values
Different ways to loop through dict contents
Working with dictionaries inside dictionaries
# challenges [2]
# project
# project-challenge
thread: SF Permits Analysis · reward: 50 xp
# brief
Create a quick lookup dictionary that maps permit numbers to their current status. This will power the status check feature in the permit tracking app.
# task