fastest table lookup
Jeff Shannon
jeff at ccvcorp.com
Mon Oct 25 17:04:59 EDT 2004
Jeff Shannon wrote:
> Neal D. Becker wrote:
>
>> I need a fairly small lookup table, and I'm wondering which data
>> python data
>> structure would be fastest. I could use a list, tuple, dictionary,
>> numeric
>> array, or maybe plain python array. The table would be indexed by
>> simple
>> integers and would be dense (filled).
>>
>>
>
> Which data structure will be fastest depends to some degree on the
> exact usage that it's being put to, but in most cases I expect that a
> dictionary will be the best bet. IIRC, [...]
So it seems that I *didn't* remember correctly. Nevermind what I said
there. (I suspect I may have been thinking of insertions rather than
accesses...)
Anyhow, it's still true that the best option depends on the exact
usage. Make a test harness that will fairly closely mimic your
lookup-table usage, and test the performance of each type of data
structure. It should be a relatively easy and straightforward experiment...
Jeff Shannon
Technician/Programmer
Credit International.
More information about the Python-list
mailing list