Nested Lists Assignment Problem

Licheng Fang fanglicheng at gmail.com
Wed Apr 26 04:51:06 EDT 2006


Dennis Lee Bieber wrote:
> On 26 Apr 2006 01:13:20 -0700, "Licheng Fang" <fanglicheng at gmail.com>
> 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/Winter2000-01/E-Shop/Python/Doku/The%20Whole%20Python%20FAQ.htm#4.50
> --
>  > ============================================================== <
>  >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
>  >      wulfraed at dm.net     |       Bestiaria Support Staff       <
>  > ============================================================== <
>  >           Home Page: <http://www.dm.net/~wulfraed/>            <
>  >        Overflow Page: <http://wlfraed.home.netcom.com/>        <

Thank you very much!

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.

>>> a = [0] * 2
>>> a
[0, 0]
>>> a[0] = 1
>>> a
[1, 0]




More information about the Python-list mailing list