checking if an object IS in a list

nicolas.pourcelot at nicolas.pourcelot at
Fri Jul 18 13:49:04 CEST 2008

On 18 juil, 13:13, Peter Otten <__pete... at> wrote:
> nicolas.pource... at wrote:
> > In fact, 'any(myobject is element for element in mylist)' is 2 times
> > slower than using a for loop, and 'id(myobject) in (id(element) for
> > element in mylist)' is 2.4 times slower.
> This is not a meaningful statement unless you at least qualify with the
> number of item that are actually checked. For sufficently long sequences
> both any() and the for loop take roughly the same amount of time over here.

Sorry. I used short lists (a list of 20 floats) and the element
checked was not in the list.
(That was the case I usually deals with in my code.)

More information about the Python-list mailing list