checking if an object IS in a list

nicolas.pourcelot at gmail.com nicolas.pourcelot at gmail.com
Fri Jul 18 07:49:04 EDT 2008


On 18 juil, 13:13, Peter Otten <__pete... at web.de> wrote:
> nicolas.pource... at gmail.com 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