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

Paul Rudin paul.nospam at
Sun Nov 8 08:07:25 CET 2009

kj < at> 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