Problem 2 --------- (a) We get an error message telling us that [2, 3] is not an element in L and therefore cannot be removed. Note that [2, 3] is an element in L[3], but not in L. (b) Assigning a value to L[1][0] changes L in place. Specifically, the item with index 0 in the item L[1] is replaced by "c". In other words, "hello" is replaced by "c" and L becomes [100, ['c', 'bye'], 1000, [[1, 2], [2, 3], [3, 4]], 1000, 900L] Problem 3 --------- (a) Yes, L1 and L2 are identical. The statements L1.append(index) and L2 = L2 + [index] have the same effect on the two lists. (b) However, what happens behind the scenes in each of these statements is quite different. L1.append(index) is an in place operation and it takes constant time, i.e., time that is independent of the length of L1. On the other hand, L2 = L2 + [index] involves creation of a new list when the right hand side of the assignment is evaluated. This means that the time it takes to evaluate this statement is proportional to the size of L2. So as L1 and L2 grow, the append operation stays fast but the L2 = L2 + [index] operation becomes increasingly slow. Problem 5 --------- The output produced by the code fragment in Problem 4 is [2, 3, 4, 5, 6, 10] [2, 3, 4, 5, 6] [2, 3, 4, 5, 6, 10] [2, 3, 4, 5, 6, 20] whereas the output produced by the code fragment in Problem 5 is [2, 3, 4, 5, 6, 10] [2, 3, 4, 5, 6, 10] [2, 3, 4, 5, 6, 10, 20] [2, 3, 4, 5, 6, 10, 20] In the first code fragment the statement L = L + [10] causes L to be assigned a new list. In other words, a new list [2, 3, 4, 5, 6, 10] is created and L is a "sticky note" attached to a reference to this new list. LL remains a "sticky note" attached to a reference to the list [2, 3, 4, 5, 6]. Thus L and LL are pointing to physically distinct lists and what we do with one list has no affect on the other. In the second code fragment, L and LL point to the same physical list to start with and then continue to do so throughout the code. Specifically, L.append(10) is an in place operation and does not result in L pointing to a physically new list. Problem 6 --------- def removeAll(L, n): while n in L: L.remove(n)