Bug or not ?
Changsen Xu
cxu1 at nd.edu
Fri May 4 07:15:16 EDT 2001
Hi all,
I met a problem, not sure it's bug or not, same
for Python version through1.5.2 to 2.0:
>>> x= [ [0,0], [0,0] ]
>>> x
[[0, 0], [0, 0]]
>>> x[0][0] = 1
>>> x
[[1, 0], [0, 0]] ## This is exactly what I expect, same as
C/C++
>>> x = [ [0]*2 ] * 2
>>> x
[[0, 0], [0, 0]]
>>> x[0][0] =1
>>> x
[[1, 0], [1, 0]] ## This result differ from above
Anybody can give me an explanation ? Thanks in advance.
I was driven crazy to check my how-can-it-be-wrong
tiny program dozens of times until I finally found the above
difference!
More information about the Python-list
mailing list