Creating a List of Empty Lists

Robin Becker robin at
Sat Dec 6 19:29:44 CET 2003

In article <Xns9447973F01BFduncanrcpcouk at>, Duncan Booth
<duncan at> writes
>The recommended way these days is usually:
>    a = [ [] for i in range(10) ]
>That still has a loop and works by appending empty lists, but at least its 
>just a single expression. Also you can incorporate the next stage of your 
>initialisation quite easily:
>    a = [ [b] for b in range(10) ]
I seem to remember the fastest way to do this was map(list,n*[[]]) from
a couple of earlier threads, but is that true in 2.3?
Robin Becker

More information about the Python-list mailing list