Jorge Vargas <[EMAIL PROTECTED]> 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? > >>>> def inplusplus(value,listObj): >... for i in listObj: >... if i is value: >... return value >... return False >...
try: obj = listObj[listObj.index(value)] # do something with obj except ValueError: # do whatever you're going to do if inplusplus returns False Assuming you meant "if i == value" (as others have pointed out). -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- http://mail.python.org/mailman/listinfo/python-list