Programming, problem solving, and algorithms

CPSC 203, 2026 W1

September 22, 2026

Announcements

  • Lab 2 and POTW 2 now available.

  • Practice examlet 1 now available.

  • Treat “Problems of the Week” as “Problems of the Day”: Spend 15 minutes to do a little programming each day.

Marimo

We will be using marimo for our more involved Python coding exercises.

  • Similar to Jupyter Lab from CPSC 103, but has some (beneficial) differences.

Open the List Activity on PrairieLearn and choose the List Mysteries question.

Python Lists

List Activity

Let’s explore some surprising list behaviors.

Inside the workspace there are other 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.

Lists: A Quick Review

Lists are ordered collections that can hold any type of data.

We can:

  • Access elements by index: provinces[0]
  • Slice: numbers[1:3]
  • Get length: len(provinces)

Adding to Lists

What about provinces.append(['Ontario', 'Quebec'])?

List Aliasing

Assignment doesn’t copy lists!

  • It creates another reference to the same list.
  • Let’s look at that in Python Tutor

Shallow Copy

copy() only copies the outer list. The inner lists are still shared!

Deep Copy

Use deepcopy() when you have nested structures (lists of lists, lists of objects).

References

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.

List Comprehensions

A compact way to create lists:

Both produce: [0, 1, 4, 9, 16]

List Comprehensions with Conditions

Notice the difference: if at the end filters, if/else before for transforms.