Re: [Tutor] Handling Generator exceptions in Python 2.5

2009-06-20 Thread Joe
Dave, Thanks for enlightening me and providing a solution. I am a recent Python convert (from Perl). Hence the confusion about generators.(Coroutines are not a standard part of Perl anyway) - Joe Dave Angel wrote: Joe Python wrote: I have a generator as follows to do list calculations. *

Re: [Tutor] Handling Generator exceptions in Python 2.5

2009-06-19 Thread Dave Angel
Joe Python wrote: 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 (wi

Re: [Tutor] Handling Generator exceptions in Python 2.5

2009-06-19 Thread Alan Gauld
"Joe Python" wrote *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)'. You could use an 'or' sidef

Re: [Tutor] Handling Generator exceptions in Python 2.5

2009-06-19 Thread Joe Python
Thanks everyone for the responses. - Joe On Fri, Jun 19, 2009 at 11:09 AM, vince spicer wrote: > Well* > > *result = [(ListA[i] - ListB[i-1])/ListA[i] for i in range(len(ListA))*if > not ListA[i] == 0*] > > will exclude any results where listA[i] is 0, if you still want these in > the result >

Re: [Tutor] Handling Generator exceptions in Python 2.5

2009-06-19 Thread vince spicer
Well* *result = [(ListA[i] - ListB[i-1])/ListA[i] for i in range(len(ListA))*if not ListA[i] == 0*] will exclude any results where listA[i] is 0, if you still want these in the result you may want to use good'ol for statement instead of list comprehension results = [] for x in range(len(listA))

[Tutor] Handling Generator exceptions in Python 2.5

2009-06-19 Thread Joe Python
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)'.