If you have the following list of lists:
>> A = [[1], [2]]
And then say you assign the 2nd list to the first list by:
>> A[0] = A[1]
You end up with the following:
>> print A
[[2], [2]]
So A[0] and A[1] point to the same list now. If you append an element to the first by:
>> A[0].append(3)
You will get the following:
>> print A
[[2,3], [2,3]]
However, if you try to delete the first list by:
>> del A[0]
Then only one list is removed, as follows:
>> print A
[[1,2]]
Q1.1: Why is the behavior different? One might expect both lists to be removed.
Clearly, if one just wants to make a copy of A[1] then the following works correctly:
>> A = [[1], [2]]
>> A[0] = list(A[1])
>> print A
[[2], [2]]
>> A[0].append(3)
>> print A
[[2,3], [2]]
The problem with this is that its running time is linear with the size of the list to copy, i.e., A[1].
Q1.2: Can one copy a list from another without linear-time copy operation?