"Jorge Vargas" <[EMAIL PROTECTED]> writes:
> 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

That's bug-prone.  Suppose the object's value is false (i.e.  it's the
empty string, or None, or the boolean False, or whatever)?  You're
best off raising an exception if the value is not found.  You could
also do something like that using the list.index method.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to