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

Paul Rudin paul.nospam at rudin.co.uk
Sun Nov 8 02:07:25 EST 2009


kj <no.email at please.post> writes:

> The best I can come up with is this:
>
> arr = [None] * 1000000
>
> Is this the most efficient way to achieve this result?
>

Depends on what you take as given. You can do it with ctypes more
efficiently, but you can also shoot yourself in the foot.

Another possibility is to use a numpy array.




More information about the Python-list mailing list