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


http://www.python.org/peps/pep-0218.html
 
Available as sets.Set in 2.3, and the builtin set (and frozenset) in
2.4.

Tim Delaney 

-----Original Message-----
From: python-list-bounces+tdelaney=avaya.com at python.org
[mailto:python-list-bounces+tdelaney=avaya.com at python.org] On Behalf Of
Daniel Eloff
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
needkeys?



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/20040720/76ffac8a/attachment.html>


More information about the Python-list mailing list