Populating a dictionary, fast [SOLVED]

Hrvoje Niksic hniksic at xemacs.org
Tue Nov 13 14:18:20 EST 2007


Francesc Altet <faltet at carabos.com> writes:

> I don't know exactly why do you need a dictionary for keeping the
> data, but in case you want ultra-fast access to values, there is no
> replacement for keeping a sorted list of keys and a list with the
> original indices to values, and the proper list of values.  Then, to
> access a value, you only have to do a binary search on the sorted
> list, another lookup in the original indices list and then go
> straight to the value in the value list.

Actually, dictionary lookup is faster than binary search because it
doesn't need to search through the table at all, it simply pinpoints
the value (most of the time).



More information about the Python-list mailing list