[Tutor] Handling Generator exceptions in Python 2.5

Joe Python jopython at gmail.com
Fri Jun 19 16:55:51 CEST 2009


I have a generator as follows to do list calculations.

*result = [(ListA[i] - ListB[i-1])/ListA[i] for i in range(len(ListA))]*

The above generator, throws  '*ZeroDivisionError*' exception if ListA[i] =
0.
Is there a way to say 'Don't divide by ListA[i] if its equal to 0 (within
that statement)'.

Sorry if this question sounds too stupid.

TIA
Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090619/a141661e/attachment.htm>


More information about the Tutor mailing list