list of empty lists

Andrei Kulakov ak at silmarill.org
Tue Mar 26 22:53:12 EST 2002


In article <3CA11A5B.5000501 at bioeng.ucsd.edu>, Curtis Jensen wrote:
> Is there a easy way to make a list of an arbitray number of empty lists?
> 
> I can do something like:
> >>> some_number = 3
> >>> l = [[]] * some_number
> >>> l
> [[], [], []]
> 
> Unfortunatly this has an unfortunate side affect.  Whatever I do to one 
> of the list gets done to the other lists. ie:
> >>> l[0].append(1)
> >>> l
> [[1], [1], [1]]
> 
> 
> In this case, what I would like is three independantly empty lists.  I 
> can make a for loop to loop "some_number" of times and append an empty 
> list at each itteration.  Is there a simpler way?
> Thanks.
>
I think loop is the simplest way.

> 


-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



More information about the Python-list mailing list