There is no way to create a big nested list without references using the
multiplication operator.
'*' is supposed to work like + ... + in this cases:
>>> a=[0, 0]
>>> b=[a[:]]+[a[:]]
>>> b
[[0, 0], [0, 0]]
>>> b[0][0]=1
>>> b
[[1, 0], [0, 0]]
Ok! Copy here, not reference. Mainly because we use [:] explicitly
expressing we want a copy.
>>> c=[a[:]]*2
>>> c
[[0, 0], [0, 0]]
>>> c[0][0]=2
>>> c
[[2, 0], [2, 0]]
Inconsistence here. It is supposed to be clear and copy, not reference
in between.
Consequence: there is no clear way to create a nested list of, lets say,
60x60, using multiplications.
Even when using this, we cannot deal with the problem:
>>> import copy
>>> d=[copy.deepcopy(a[:])]*2
>>> d
[[0, 0], [0, 0]]
>>> d[0][0]=3
>>> d
[[3, 0], [3, 0]]
Workaround:
>>> from numpy import *
>>> a=zeros((2,2),int)
>>> a
array([[0, 0],
[0, 0]])
>>> b=a.tolist()
>>> b
[[0, 0], [0, 0]]
>>> b[0][0]=4
>>> b
[[4, 0], [0, 0]]
And that is the expected behaviour.
Thanks.
