Sorted list as an alternative to dictionary for when you only needkeys?
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Tue Jul 20 00:02:51 CEST 2004
Available as sets.Set in 2.3, and the builtin set (and frozenset) in
From: python-list-bounces+tdelaney=avaya.com at python.org
[mailto:python-list-bounces+tdelaney=avaya.com at python.org] On Behalf Of
Sent: Tuesday, 20 July 2004 6:19 AM
To: python-list at python.org
Subject: Sorted list as an alternative to dictionary for when you only
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list