implementation of "in" that returns the object.

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Oct 22 10:53:47 EDT 2006


In <mailman.939.1161527588.11739.python-list at python.org>, Jorge Vargas
wrote:

> I need to check if an object is in a list AND keep a reference to the
> object I have done it this way but is there a better one?

But you already *have* a reference to that object!?

>>>> def inplusplus(value,listObj):
> ...     for i in listObj:
> ...             if i is value:
> ...                     return value
> ...     return False
> ...

def my_in(value, sequence):
    if value in sequence:
        return value
    else:
        return False

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list