Licheng Fang wrote:
>Dennis Lee Bieber wrote:
>
>
>>On 26 Apr 2006 01:13:20 -0700, "Licheng Fang" <[EMAIL PROTECTED]>
>>declaimed the following in comp.lang.python:
>>
>>
>>
>>
>>>Could anybody please explain to me why three values were change? I'm
>>>bewildered. Thanks!
>>>
>>>
>>http
"Licheng Fang" wrote:
> But I still wonder why a nested assignment "a = [[0]*3]*3" generates 3
> references to the same list, while the commands below apparently do
> not.
that's because they're replacing a list item, rather than modifying it.
a = [0] * 2
a
> [0, 0] <- now you have two
"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. Th
Dennis Lee Bieber wrote:
> On 26 Apr 2006 01:13:20 -0700, "Licheng Fang" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>
> >
> > Could anybody please explain to me why three values were change? I'm
> > bewildered. Thanks!
>
> http://www.aifb.uni-karlsruhe.de/Lehrangebot/Winte
Le Mercredi 26 Avril 2006 10:13, Licheng Fang a écrit :
> 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 thre
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://mail.python.org/mail