473,466 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

fast list lookup

Hello,

what is the fastest way to determine whether list l (with
len(l)>30000) contains a certain element?
Klaus
Jul 18 '05 #1
4 1290
On Wed, 26 Jan 2005 06:45:29 -0800 (PST), Klaus Neuner
<kl************@yahoo.de> wrote:
what is the fastest way to determine whether list l (with
len(l)>30000) contains a certain element?


If the list isn't sorted, I doubt you'll do better than

if an_element in my_list:
# do whatever

If the list is sorted, have a look at the bisect module.

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 18 '05 #2
Klaus Neuner <kl************@yahoo.de> wrote:
what is the fastest way to determine whether list l (with
len(l)>30000) contains a certain element?


"if thecertainelement in l:"

is the fastest way unless there are properties of l which you're not
telling us about, or unless what you need is not just to determine
whether l contains a certain element but rather something different
(such as doing the same determination for several elements on an
unchanging l).
Alex
Jul 18 '05 #3
Klaus Neuner wrote:
Hello,

what is the fastest way to determine whether list l (with
len(l)>30000) contains a certain element?


If you can use a set or dict instead of a list this test will be much faster.

Kent
Jul 18 '05 #4
>> what is the fastest way to determine whether list l (with
len(l)>30000) contains a certain element?


Either a sorted list (in conjunction with the bisect-module) or a
dictionary is your friend...

Regards,
Marco

Jul 18 '05 #5

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

Similar topics

11
by: Ville Vainio | last post by:
I need a dict (well, it would be optimal anyway) class that stores the keys as strings without coercing the case to upper or lower, but still provides fast lookup (i.e. uses hash table). >> d...
8
by: Neil | last post by:
I have a very puzzling situation with a database. It's an Access 2000 mdb with a SQL 7 back end, with forms bound using ODBC linked tables. At our remote location (accessed via a T1 line) the time...
14
by: WindAndWaves | last post by:
Hi Gurus What is the fatest way to select all the items in a list box? At the moment, I do this for each itm in ctl..... type of method, but with more than 2,000 items, this can be a little...
7
by: Guyon Morée | last post by:
hi all, i have a big list of tuples like this: etc now i have another big(ger) list of tuples like this: etc
10
by: javuchi | last post by:
I just want to share some code with you, and have some comments and improvements if you want. This header file allocates and add and delete items of any kind of data from a very fast array: ...
2
by: Spoon | last post by:
Hello, I'm wondering whether the STL defines a data structure with the following features: o provides push_front() and pop_back() (like std::list) to implement a FIFO buffer. o allows fast...
4
by: jehugaleahsa | last post by:
Hello: I have a List<Twhere the internal arrays are of a fixed size. I want to be able to take an index of, say, {1, 3} and quickly move to the next nth position. So say I have a method that...
14
by: Karch | last post by:
I need to find the fastest way in terms of storage and searching to determine if a given string contains one of a member of a list of strings. So, think of it in terms of this: I have a string such...
12
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, I have a dictionary like this: Dictionary<List<string>, List<string>> How can I iterate in it? Thanks very much. -- Luigi
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.