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

Andre Engels andreengels at gmail.com
Sat Nov 7 14:33:29 EST 2009


On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez
<kyrie at uh.cu> wrote:
>
> Quoting Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr>:
>
>> > Another situation where one may want to do this is if one needs to
>> > initialize a non-sparse array in a non-sequential order,
>>
>> Then use a dict.
>
> Ok, he has a dict.
>
> Now what? He needs a non-sparse array.

Let d be your dict.

Call the zeroeth place in your array d[0], the first d[1], the 10000th
d[100000].


-- 
André Engels, andreengels at gmail.com



More information about the Python-list mailing list