Sorted list as an alternative to dictionary for when you only need keys?
Daniel Eloff
danieleloff at hotmail.com
Mon Jul 19 16:18:58 EDT 2004
I've used a dictionary with None values before when I've needed a
container with fast lookup by value. Just insert all the values as keys.
But this is not optimal at all. Better would be a python list that is
sorted and uses a binary search algo to find values. Now it's not that
much work to write a wrapper class for list that does this, but is there
maybe not such a thing already in Python (surely it's very common, it's
like a C++ STL set or a .NET sorted list, or a.). Or at least a wrapper
already written in Python.
I think this really should be a data structure added to the language, if
it isn't already.
-Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040719/858e42d0/attachment.html>
More information about the Python-list
mailing list