idiom for initial list of lists

Robin Becker robin at jessikat.fsnet.co.uk
Mon Sep 11 00:56:03 CEST 2000


In article <pvg0n86o71.fsf at kurma.research.nokia.com>, Pekka Pessi
<Pekka.Pessi at nokia.com> writes
>In message <Pine.LNX.4.21.0009081645290.1107-100000 at fep132.fep.ru> Oleg 
>Broytmann <phd at phd.russ.ru> writes:
>>> so I'm forced to use the rather pedantic
>>> S=[]
>>> for i in range(n): S[i].append([])
>
>>   That's the only and one correct way.
>
>        I prefer list():
>
>>>> a = map(list, 5 * [[]])
>>>> a[0].append(1)
>>>> a
>[[1], [], [], [], []]
>
>        or 
>
>>>> a = map(list, 5 * ((),))
>>>> a
>[[], [], [], [], []]
>>>> a[0].append(1)
>>>> a
>[[1], [], [], [], []]
>
>                                        Pekka
yes that's the same time as the fastest I could get with a C extension
copy.
-- 
Robin Becker



More information about the Python-list mailing list