Most efficient way to "pre-grow" a list?
emily at nospam.com
Fri Nov 6 19:11:47 CET 2009
"Andre Engels" <andreengels at gmail.com> wrote in message
news:mailman.2696.1257520404.2807.python-list at python.org...
>On Fri, Nov 6, 2009 at 1:12 PM, kj <no.email at please.post> wrote:
>> arr = [None] * 1000000
>> Is this the most efficient way to achieve this result?
> It depends - what do you want to do with it? My first hunch would be
> to use a dictionary instead of a list, then the whole problem
> disappears. If there is a reason you don't want to do that, what is
> André Engels, andreengels at gmail.com
I second this. It might seem a sensible thing to do in perl, but I can't
imagine what you would actually want to do it for! Seems like an odd thing
to want to do!
More information about the Python-list