My program has two lists of numbers. What I want to do is to iterate over the zip list obtained doing zip()
, apply two different functions on the two intermediate variables and save the first result (apply compute_add()
) in one list and the second (apply compute_sub()
) in another. I can do it iterating two times on the zip list but I'm wondering if there is a way to do so in one shot.
Here is my code, of course is not running.
def compute_add(_x, _y):
return _x * _y + 10
def compute_sub(_x, _y):
return _x * _y - 10
list1 = [1, 2, 3, 4, 5]
list2 = [10, 20, 30, 40, 50]
res1, res2 = [compute_add(x, y), compute_sub(x, y) for x, y in zip(list1, list2)]
Any suggestions?