A bug?

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Mon Oct 27 12:17:57 EDT 2014


On 10/27/2014 05:01 PM, umatrp at 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/






More information about the Python-list mailing list