Nested Lists Assignment Problem
Fredrik Lundh
fredrik at pythonware.com
Wed Apr 26 07:01:42 EDT 2006
"Licheng Fang" wrote:
>I wanna use nested lists as an array, but here's the problem:
>
>>>> a = [[0]*3]*3
>>>> a
> [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>>> a[0][0] = 1
>>>> a
> [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
>
> Could anybody please explain to me why three values were change? I'm
> bewildered. Thanks!
http://pyfaq.infogami.com/how-do-i-create-a-multidimensional-list
</F>
More information about the Python-list
mailing list