Handle Exceptions Inside List Comprehension

beginner zyzhu2000 at gmail.com
Mon Oct 29 10:47:52 EDT 2007


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




More information about the Python-list mailing list