Python Reading
- Read the chapter entitled Lists
from section "Repetitions and References" through section "List Comprehensions". (You may skip the section entitled "The Return of L-Systems".)
Key Ideas
- List Methods
- append(item)
- insert(position, item)
- pop() or pop(position)
- sort()
- reverse()
- index(item)
- count(item)
- remove(item)
- List Append vs. List Concatenation
- for loop list traversal
- A function parameter can be a list
- A pure function does not modify its parameters.
In general, modifying a parameter can produce an undesirable
side effect and should be avoided.
- A function can return a list
- List Comprehensions (this is a shortcut and is optional to understand)
- [<expression> for <item> in <sequence>]
- [<expression> for <item> in <sequence> if <condition>]
Active Learning
Suppose that the insert(position, item) method does not exist.
- Implement the insert(position, item) method using a for loop.
- Implement the insert(position, item) method using a while loop.
- Implement the insert(position, item) method using recursion.
- Which of these implementations is best?