fast list lookup

Simon Brunning simon.brunning at gmail.com
Wed Jan 26 09:48:16 EST 2005


On Wed, 26 Jan 2005 06:45:29 -0800 (PST), Klaus Neuner
<klaus_neuner82 at 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,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list