implementation of "in" that returns the object.
Fredrik Lundh
fredrik at pythonware.com
Sun Oct 22 11:01:56 EDT 2006
Marc 'BlackJack' Rintsch wrote:
>>>>> 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
however,
>>> a = [1.0, 2, 3]
>>> my_in(1, a)
1
>>> my_in(2.0, a)
2.0
>>> my_in(3L, a)
3L
so it all depends on what the OP means by "is in".
</F>
More information about the Python-list
mailing list