A list is an important data structure that allows us to store multiple values under one name, similar to how we can store multiple characters (e.g., letters) in one string. In fact, both lists and strings are sequences, a category of types for positionally ordered collections of items. (E.g., a string is a collection of characters ordered by the indices, 0, 1, 2, ..., n-1, where n is the length of the string.) We also introduce another sequence called the tuple, but our focus will be on lists since the list is more flexible.

Lessons - watch before lecture

  1. Tuple Expressions (8 minutes) A tuple is a simple sliceable type
  2. List Expressions (5 minutes) The list is one of Python's most useful built-in types. A list is mutable, unlike a string or a tuple.
  3. Slice Visualization (4 minutes) How do we visualize lists? As a sequence, a list can be sliced. A slice of a list is a new list.
  4. List Methods (3 minutes) There are many list methods, some of them you have seen before when we discussed strings.
  5. Mutable List Functions (4 minutes) We can define functions that modify the values in a list, just like we can define functions that modify attribute values in an object.

OR read 10.0 - 10.2, 10.4 - 10.6, 10.8 - 10.13

Lecture materials

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

Examples: swapper.py, shapes.py (to provide class Point3, same as Lecture 7))
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 11, 13, 17, 21, 23, 28, and 30: See the lecture slides file above for the questions. After solving the problems yourself, you can check your answers here.