Newbie Q on searching lists

Kenny Tilton ktilton at nyc.rr.com
Sat Nov 23 03:26:57 EST 2002


Sean 'Shaleh' Perry wrote:
> On Friday 22 November 2002 21:45, Kenny Tilton wrote:
> 
>>I see the index method on lists throws an error if the element sought is
>>not found. I was hoping it would return None.
>>
>>The semantics I am coding happen to throw an error if a certain element
>>is found in a list, so i want to code:
>>
>>    if calculators.index[thisCalculator]:
>>       raise CircularDependency, thisCalculator
>>
>>1. Am I missing something?
>>
> 
> 
> if calculators.count(thisCalculator): # returns zero if not found
>    raise CircularDependency, thisCalculator

oops :)  thx!

-- 

  kenny tilton
  clinisys, inc
  ---------------------------------------------------------------
""Well, I've wrestled with reality for thirty-five years, Doctor,
   and I'm happy to state I finally won out over it.""
                                                   Elwood P. Dowd




More information about the Python-list mailing list