implementation of "in" that returns the object.
Jorge Vargas
jorge.vargas at gmail.com
Sun Oct 22 10:33:04 EDT 2006
Hi
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?
>>> def inplusplus(value,listObj):
... for i in listObj:
... if i is value:
... return value
... return False
...
>>> l = [1,2,3,4]
>>> print inplusplus(2,l)
2
>>> print inplusplus(9,l)
False
>>> print inplusplus(1,l)
1
>>> l.append(0)
>>> print inplusplus(0,l)
0
More information about the Python-list
mailing list