I'm a bit puzzled with converting following lambda function into a regular function:
my_fun = lambda x,y:[i(j) for i,j in zip(x,y)]
where x is a list of types, say
types = [float,float,float]
and where y is a list of integer values, say:
values = [1,2,3]
so, basically my_fun() converts integers into floats. When I run it this way:
new_values = my_fun(types,values)
it returns a new list with floats.
Now when it comes to define a function in a regular way:
def my_fun(x,y):
for i,j in zip(x,y):
i(j)
it stops working. I'm not putting return inside / outside of a loop as it will obviously return first / last instance once it hits it and not trying to assign a new list like:
def my_fun(x,y):
new_vals = []
for i,j in zip(x,y):
new_vals.append(i(j))
return new_vals
because in this case this function looks to overwhelmed to me. Can someone please explain fundamental difference between lambda and regular function in my case, as it seems I am missing some simple basic knowledge about Python 3.6?
I thought it might have been for list-comprehension I'm using in my lambda but I couldn't explain it to myself. Many thanks!