Most efficient way to "pre-grow" a list?

Paul Rubin http
Fri Nov 6 07:34:08 EST 2009


kj <no.email at please.post> writes:
> >>> arr[999] = 42
>    ...
> The best I can come up with is this:
> arr = [None] * 1000000
> Is this the most efficient way to achieve this result?

If you're talking about an array of ints, use the array module.
You might also look at numpy.



More information about the Python-list mailing list