def gen_reciprocals(seq, error_callback):
for item in seq:
if item == 0:
error_callback(item)
else:
yield 1.0/item
def an_error_occurred(value):
print(f"An error occurred trying to find the reciprocal of {value}")
for x in gen_reciprocals([1,0,2], an_error_occurred):
print(x)