Re: Nested Lists Assignment Problem

2006-04-26 Thread Gary Herron
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

Re: Nested Lists Assignment Problem

2006-04-26 Thread Fredrik Lundh
"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

Re: Nested Lists Assignment Problem

2006-04-26 Thread Fredrik Lundh
"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

Re: Nested Lists Assignment Problem

2006-04-26 Thread Licheng Fang
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

Re: Nested Lists Assignment Problem

2006-04-26 Thread tiksin
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

Nested Lists Assignment Problem

2006-04-26 Thread Licheng Fang
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