[ [ [] * y for y in range(3) ] * x for x in range(2) ]

Chirayu Krishnappa thephoenix235 at gmx.net
Thu Jan 30 07:37:04 CET 2003


This is whats wrong.

>>> L=[[[]]*3]*2
>>> L
[[[], [], []], [[], [], []]]
>>> L[0][0]=1
>>> L
[[1, [], []], [1, [], []]]

Chirayu.

On Wed, 29 Jan 2003 22:01:51 -0800, David Eppstein
<eppstein at ics.uci.edu> wrote:

>In article <2463d77d.0301292034.1fdc47bd at posting.google.com>,
> marcel_achim at videotron.ca (Marcel) wrote:
>
>> I'm trying to allocate nested lists up-front using the subject line,
>> instead of generating :
>> [ [ [], [], [] ], [ [], [], [] ] ]
>> I end up with  :
>> [ [], [ [], [], [] ] ]
>
>What's wrong with [[[]]*3]*2  ?





More information about the Python-list mailing list