# Outline for October 13, 2021

Reading: §6.9–6.10, 4.9
Due: Homework 2, due October 20, 2021

1. What you can do with lists
1. Check membership: in, not in
2. +: concatenation
3. *: repetition
4. list[a:b]: slice list from a to b−1
5. del list[i]: delete element list[i]; i can be a slice
6. Add elements to, remove elements: L.append(x), L.extend(ls), L.insert(i, x), L.pop(), L.remove(x)
7. Element ordering: L.reverse(), L.sort()
8. Other: L.count(x), L.index(x)

2. Searching a list
1. Example use: linear search [linsearch.py]

3. Lists as parameters: can change list elements in function and they are changed in caller [args2.py]

4. More on parameters: named arguments and variable number of arguments [args3.py]

5. isinstance(obj,type) function
1. type is bool, float, int, list, str, tuple

6. Recursion
1. n factorial [nfact.py]

7. Thinking recursively [recfun.py]
1. First: think of the recursive case (write the problem in terms of something involving a smaller instance of the problem)
2. Next: think of base case (when to stop)
3. Example: Find the length of a string
4. Example: Does the string only have alphabetic characters in it?
5. Example: Find the maximum element of a list
6. Example: Construct a string from a list of strings
7. Example: Reverse a string

8. Recursion
1. Palindromes [palindrome.py]
2. Fibonacci numbers [rfib.py]
3. Sum of digits [sumdigits.py]
4. Greatest common divisor [gcd.py]
5. Nested lists: is an item in a list? [isinlist.py]
6. Tower of Hanoi [hanoi.py]

 Matt Bishop Office: 2209 Watershed Sciences Phone: +1 (530) 752-8060 Email: mabishop@ucdavis.edu
ECS 235A, Computer and Information Security
Version of October 12, 2021 at 9:24PM

You can also obtain a PDF version of this.