473,385 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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: py***************************************@python.o rg
[mailto:py***************************************@p ython.org]Per conto di
Daniel Eloff
Inviato: lunedi 19 luglio 2004 22.19
A: py*********@python.org
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

Jul 18 '05 #1
0 1554

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Der Andere | last post by:
I need to implement a sorted (ordered) list. STL has no sorted list type as far as I know. Is there a (straight) way to implement a sorted list using STL? BTW: The type of items in the list will...
3
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** it's been a while since i have poseted to this newsgroup, but for a long time i was not programming at all. but now that i am out of...
4
by: Cybertof | last post by:
Hi ! I would like to make an array of structure (collection ?) that would behave like an advanced sorted list : a sorted list with one key but with multiple values (sorted lists are key/value...
13
by: vd12005 | last post by:
Hello, i would like to sort(ed) and reverse(d) the result of many huge dictionaries (a single dictionary will contain ~ 150000 entries). Keys are words, values are count (integer). i'm...
11
by: John | last post by:
I am coding a radix sort in python and I think that Python's dictionary may be a choice for bucket. The only problem is that dictionary is a mapping without order. But I just found that if the...
2
by: loial | last post by:
The following code gives the error d=sortedmachines TypeError: list indices must be integers What works for the unsorted dictionary does not work for the sorted dictionary. Can anyone help?
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
3
by: =?Utf-8?B?YW1pcg==?= | last post by:
Hi, I have a Generic Object that has a private List field item. I populate the List in a different function I use a FOREACH LOOP with a FindAll function to get all items that have a certain...
1
by: Harold Howe | last post by:
Howdy all, The msdn help says this about SorteList<k,v>: "If the list is populated all at once from sorted data, SortedList is faster than SortedDictionary." My question is this: how do I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.