You cannot. try
is a (compound) statement, a list-comprehension is an expression. In Python these are completely distinct things and you cannot have a statement inside an expression.
The thing you can do is using a wrapper function:
def add_handler(handler, exc, func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except exc:
return handler(*args, **kwargs) # ???
return wrapper
Then used as:
my_truediv = add_handler(print, ZeroDivisionError, truediv)
Note that this is very limited. You must return a value and insert it into the resulting list, you can't simply "skip it".
You should simply do:
from operator import truediv
result_list = []
for i, j in zip(list1, list2):
try:
result_list.append(i/j)
except ZeroDivisionError:
pass
Alternatively, if you simply want to skip those values you can just filter them out:
map(lambda x_y: truediv(*x_y), filter(lambda x_y: x_y[1] != 0, zip(list1, list2)))