CPSC 203, 2025 W2
January 20, 2026
Let’s explore some surprising list behaviors.
Open the List Activity on PrairieLearn.
Inside the workspace there are 4 files, each containing a short sequence of exercises. Complete them, and then we’ll review together.
Be curious. Feel free to experiment by changing things!
Write down surprising behaviors.
10:00
Lists are ordered collections that can hold any type of data.
We can:
provinces[0]numbers[1:3]len(provinces)What about provinces.append(['Ontario', 'Quebec'])?
Assignment doesn’t copy lists – it creates another reference to the same list.
.copy() only copies the outer list. The inner lists are still shared!
Use deepcopy when you have nested structures (lists of lists, lists of objects).
Variables are names that refer to objects in memory.
Think of it like sticky notes on boxes - m1 and m2 are two sticky notes on the same box.
A compact way to create lists:
Both produce: [0, 1, 4, 9, 16]
Notice the difference: if at the end filters, if/else before for transforms.
.copy() only copies the outer structurecopy.deepcopy() copies everything