creating really big lists
Delaney, Timothy (Tim)
tdelaney at avaya.com
Wed Sep 5 19:34:44 EDT 2007
Hrvoje Niksic wrote:
> Dr Mephesto <dnhkng at googlemail.com> writes:
>
>> I would like to create a pretty big list of lists; a list 3,000,000
>> long, each entry containing 5 empty lists. My application will
>> append data each of the 5 sublists, so they will be of varying
>> lengths (so no arrays!).
>>
>> Does anyone know the most efficient way to do this? I have tried:
>>
>> list = [[[],[],[],[],[]] for _ in xrange(3000000)]
> If you're building large data structures and don't need to reclaim
> cyclical references, I suggest turning GC off, at least during
> construction.
This is good advice, but another question is whether you really want
such a list. You may well be better off with a database of some kind -
they're designed for manipulating large amounts of data.
Tim Delaney
More information about the Python-list
mailing list