Consider the following example:
def fcn_a(x, y):
return x + y
def fcn_b(x, y):
return x * y
def fcn_c(x, y):
return x / y
fcns = [fcn_a, fcn_b, fcn_c]
x = [1, 2, 3]
y = [10, 20, 30]
I need to apply the functions in fcns
to each pair of elements in x
and y
in order. Something like this:
result = []
for i in range(len(fcns)):
result.append(fcns[i](x[i], y[i]))
# result == [11, 40, 0.1]
How can I accomplish this using a list comprehension?