Outline for November 16, 2012
Reading: § 14
Assignment Due: Wednesday, November 28, 2012 at 5:00 PM
- In list, or in a list in a list, etc. [isinlist.py]
- Objects, references, aliasing
- For strings, one copy: assume a = "banana"
- After b = a or b = a[:], then a is b is True
- For lists, multiple copies: assume A = [ 1, 2, 3 ]
- After B = A, then A is B is True
- After B = A[:], then A is B is False
- List methods
- Add elements to, remove elements: L.append(x), L.extend(ls), L.insert(i, x), L.pop(), L.remove(x)
- Element ordering: L.reverse(), L.sort()
- Other: L.count(x), L.index(x)
- Example use: linear search [linsearch.py]
- Example use: recursive linear search [rlinsearch.py]
- Example use: linear search using L.index(x) [linsearchix.py]
- Tuples
- Used to group data
- Like lists, but immutable
A PDF version is available here.
|
ECS 10, Basic Concepts of Computing
Fall Quarter 2012
|