On 10/27/2014 05:01 PM, uma...@gmail.com wrote:
I use python 3.4.0 version. In the course of developing / running a python 
program, I have encountered a problem. I have reproduced below a simple program 
to bring it out.


d = [[0]*3]*4
dd = [1,2,3,4,5,6,7,8,9,10,11,12]
for i in range(4):
...   for j in range(3): d[i][j] = dd[i*3+j]
...
d
[[10, 11, 12], [10, 11, 12], [10, 11, 12], [10, 11, 12]]

d is not transferred to dd as expected?
Of course I can use 'append' & do my job (less elegantly though).


See https://docs.python.org/3/library/stdtypes.html?highlight=list#common-sequence-operations under Note 2 .

Also asked and answered multiple times at stackoverflow, e.g., http://stackoverflow.com/questions/6688223/



--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to