CPSC 203, 2026 W1
October 8, 2026
Last night, someone broke into the Vancouver Museum of Data Science.
The thief stole the legendary Golden DataFrame — an artifact said to contain the answers to all data questions.
You’ve been called in as data detectives to solve the case.

Dictionaries are Python’s data structure for storing key-value pairs.
| Key | Value |
|---|---|
| name | Prof. Histogram |
| department | Statistics |
| alibi | was at the faculty meeting |
| motive | jealousy of the DataFrame’s power |
data_heist_dictionaries.py.Dictionaries / key-value lookup is yet another way to represent compound data:
| Representation | Elements | Data |
|---|---|---|
| lists | integer indexes 0 to \(n\) | values |
| namedtuples | fields | values |
| dataclasses | attributes | values |
| row of a dataframe | columns | values |
| dictionary | keys | values |
Dictionaries are probably the most common Python representation for compound data because
And the less you have to think about your data structure, the better. Right?
Dictionaries / key-value lookup is useful for solving other common problems.
For example: Have we seen this item before?
defaultdict(bool) returns False for missing keys — no KeyError!
The thief visited both Gallery A and Gallery B before the theft.
Your mission: Find everyone who was in BOTH rooms.
Let’s try using just lists:
Let’s try using dictionaries (and lists):
Dictionary lookup is instant — it doesn’t matter how many keys are stored!
Use when: Finding common elements, detecting duplicates
Use case: Count how many times each item appears.
Could use a defaultdict(int), which would assign value of 0 to any missing key.
Alternatively, this pattern appears so often that there is an even more specialized version of a dictionary: Counter.
You found a mysterious note left by the thief:
WKLV LV WKH FRGH: GLDJRQDO
It appears to be a substitution cipher. The thief replaced each letter with another.
In English, some letters appear more often than others:
| Letter | Frequency |
|---|---|
| E | 12.7% |
| T | 9.1% |
| A | 8.2% |
| O | 7.5% |
| I | 7.0% |
If we count the letters in the cipher, the most common one is probably E!
Use case: Find two numbers that add up to a target.
As we scan, we remember what we’ve seen and check if the complement exists!
The vault has a two-dial combination lock.
Each dial shows a number, and they must multiply to 435,599.
The thief left behind a piece of paper with two lists:
Find the two numbers (one from each list) that open the vault!
Use case: Organize items into categories (like pandas’ groupby!).
We have testimony from five suspects about where they were at 8pm:
Group suspects by their alibi to find who was together!
STUDENT_heist_nb.py. You’ll solve 4 puzzles with LARGE datasets.Inspired by Advent of Code puzzles!
Dictionaries give you fast lookup by key.
The patterns we learned:
defaultdict(bool))Counter)defaultdict(list))