A list can contain anything, even other lists. When we have a list of lists, we can call it a nested list.

The dictionary is a built-in type in Python, called dict. A dictionary is a collection like a list, but unlike a list whose values are identified positionally using integer indices, the values in a dictionary are identified by keys, which can be any immutable type (e.g., string) and not just int.

Lessons - watch before lecture

  1. Nested Lists (7 minutes) Also called multidimensional lists
  2. Nested Slicing (6 minutes) Slicing a nested list makes a copy of the top-level list only; this is called a shallow copy.
  3. Defining Functions for Tables, part 1 (9 minutes) Some examples of functions that do not modify the nested list given as argument (immut.py)
  4. Defining Functions for Tables, part 2 (8 minutes) Some examples of functions that modify the nested list given as argument (mut.py)

AND read 11.1 - 11.5 on dictionaries


Lecture materials

Slides: individual slides for viewing, 6-up layout for printing

Examples: table.py (skeleton), table.py, list_2d_print.py (another version), list_2d_transpose.py
To download the above .py files, right-click (Windows) or command-click (Macs) on the filename and then select "Save link as".
This way you choose where the files will be saved, instead of having your computer save to the default folder (from which you will later have to move your files for organization).

Lecture Recording

Answers to the questions on slides 30 and 32: See the lecture slides file above for the questions. After solving the problems yourself, you can check your answers here.