R: Sorted list as an alternative to dictionary for when you onlyneedkeys?

D

Daniele Varrazzo

If you need a container to look into, there is the sets module that provides
a couple of them.

If you need a sorted list, there is the bisect module. But i don't think it
fits your need for a quick lookup: it's a python module so probably it's
slower. Furthermore you can __hash__ almost everything, but you can __cmp__
in a consistent way much less stuff.

Take definitely a look at sets.

-----Messaggio originale-----
Da: [email protected]
[mailto:p[email protected]]Per conto di
Daniel Eloff
Inviato: lunedi 19 luglio 2004 22.19
A: (e-mail address removed)
Oggetto: 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,224
Latest member
BettieToom

Latest Threads

Top