Re: Handle Exceptions Inside List Comprehension

2007-10-29 Thread Paul Rubin
beginner <[EMAIL PROTECTED]> writes: > [f(x) for x in xs] > > I want to skip the point if f(x) raises an exception. How can I do > that without totally removing the list comprehension? def ff(xs): for x in xs: try: yield f(x) except: pass [x for x in ff(xs)] or alternatively list(

Handle Exceptions Inside List Comprehension

2007-10-29 Thread beginner
Hi All, I am wondering if there is any way to handle exceptions inside list comprehension. For example, [f(x) for x in xs] I want to skip the point if f(x) raises an exception. How can I do that without totally removing the list comprehension? Thanks, Geoffrey -- http://mail.python.org