A bug?

umatrp@gmail.com trsexgl at gmail.com
Mon Oct 27 17:01:57 CET 2014


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).



More information about the Python-list mailing list