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