If x
is a list,
x * 2
Returns two times the same elements from the list.
As lists are passed by references, this means:
>>> A = 2 * [[0]]
>>> B = [[0], [0]]
Will actually not have the same structure: both A[0]
and A[1]
point to the same list, while B[0]
and B[1]
point to two different lists.
And indeed, if you try:
>>> A[0] == A[1]
True
>>> A[0] is A[1]
True
>>> A[0].append(1)
>>> A
[[0, 1], [0, 1]]
While:
>>> B[0] == B[1]
True
>>> B[0] is B[1]
False
>>> B[0].append(1)
>>> B
[[0, 1], [0]]