Newbie Q on searching lists
Terry Hancock
hancock at anansispaceworks.com
Sat Nov 23 03:34:49 EST 2002
On Friday 22 November 2002 10:21 pm, Kenny Tilton wrote:
> 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
Did you mean this?
if thisCalculator in calculators:
raise CircularDependency(thisCalculator)
Or maybe this?
if thisCalculator not in calculators:
# put the unsafe code here
else:
# alternate behavior for the special case here
(unless the condition is really rare so that it makes sense to treat it as an
error).
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Python-list
mailing list