fast list lookup

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

On Wed, 26 Jan 2005 06:45:29 -0800 (PST), Klaus Neuner
<klaus_neuner82 at> 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.

Simon B,
simon at,

More information about the Python-list mailing list