list of empty lists
Curtis Jensen
cjensen at bioeng.ucsd.edu
Tue Mar 26 20:03:23 EST 2002
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.
--
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451
More information about the Python-list
mailing list