is this a bug or what?
Justin Sheehy
justin at iago.org
Fri Dec 28 08:38:02 EST 2001
"I.J." <shiver at yubc.net> writes:
>>>> M=[[0]*3]*3
>>>> M
> [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>>> M[1][1]=1
>>>> M
> [[0, 1, 0], [0, 1, 0], [0, 1, 0]]
>
> Is this new age math?
No, and it isn't a bug either.
You made a list with three references to the same list in it. Then
you modified the list that you had three references to.
See also the FAQ:
http://www.python.org/doc/FAQ.html#4.50
-Justin
More information about the Python-list
mailing list