how to create a big list of list

greg greg at cosc.canterbury.ac.nz
Sat Jun 6 04:20:03 CEST 2009


command.bbs at alexbbs.twbbs.org wrote:

> i have try [ [] for x in xrange(2**25) ]

Are you really going to be adding data to all
of those sublists?

If you're only using them sparsely, it may be
better to use a dictionary in place of the
top level list, and only add sublists as and
when necessary.

Recent Python versions have a built-in type
called defaultdict that makes this kind of
thing easy.

-- 
Greg



More information about the Python-list mailing list