fastest table lookup
Jeff Shannon
jeff at ccvcorp.com
Mon Oct 25 15:48:55 EDT 2004
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, list (and tuple) indexing is
O(n) (with n=len(list)), while dictionary references are O(1). In some
circumstances, it may (or may not) be possible to achieve further
speedup by using a python array or numarray, but unless you're already
planning on using numarray for other things, I'd consider its usage for
a lookup table to be a premature optimization.
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list