Outline for May 13, 2009

Reading: §11.1–11.2


  1. Types of collections
    1. Lists
    2. Tuples
    3. Dictionaries
  2. Lists
    1. Mutable, unlike strings
    2. Compare to arrays in other languages
    3. Operations: concatenation, repetition, indexing, length, slicing as before
    4. Membership: x in List
    5. Equality and same object; test for same object: L1 is L2
  3. Methods for lists
    1. L.append(x): append x to L
    2. L.sort(): sort the elements of L
    3. L.reverse(): reverse L
    4. L.index(x): index of first occurrence of x in L
    5. L.insert(i, x): insert x into L at position with index i
    6. L.count(x): return the number of times x appears in L
    7. L.remove(x): delete first occurrence of x in L
    8. L.pop(i): delete the element with index i in L and return its value
  4. Example: generate list of words in file (see wl.py)