Lists & Tuples

A Python list is a sequence (ordered collection) of Python objects. Because it is a sequence like a string it shares characteristics such as indexing & slicing, iteration (for) and membership (in) as well as functions such as len(). One importance difference is that lists are mutable (strings are immutable). Tuples are immutable lists.

Readings from the book The Practice of Computing Using Python.

Chapter 7: Lists

Videos

  1. Lists
  2. A list is a sequence of Python objects delimited by square brackets and separated by commas. Any mixture of objects is allowed.

    1. Lists (Video I, Video II)
    2. Tuples (Video)
    3. Tuples are immutable lists – handy if you want a list that cannot be changed. Tuples are delimited by parentheses.

  3. Examples using lists
    1. Perfect Numbers (Video I , Video II)
    2. In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors (excluding the number itself). Here we find the perfect numbers that are less than some value.

    3. Word Puzzle. (Video I, Video II, Video III)
    4. What do these words have in common: pig, table, cab, real, yet, and ride?
      Once you figure that out, what other English words have this characteristic? Let's write a program.

  4. CSV module
    1. Reading and writing CSV files
  5. Extra reading
    This link provides detail about naming and assignment, especially with respect to immutables (such as lists) and function parameters. There isn't anything here that isn't in the book, but the information is organized differently. Understanding the details right will help you program (as well as help you on exams).

Assignments

  1. Chapter 7 Exercises on Codio
  2. Lab05 (do pre-lab first on D2L)
  3. Lab06 (do pre-lab first on D2L)
  4. Project03 in 2 weeks