I have a python function that I can pass a function argument in 2 ways as shown below.
Lambda:
res = foo(lambda x: x+2)
Regular function passing:
def func1(x):
return x + 2
res = foo(func1)
But I want to pass a slightly complex function to foo similar to the lambda function call. I can easily do this with LUA code.
LUA example:
res = foo(function (x)
local y = x * 2
if(y %2 == 0) then
return y
else
return y + 1
end
end)
How do I accomplish this with Python in a clean, programmer friendly way? All examples of lambda I see are for very minimal logic.