A regular function can have a call in its definition, no problem. I can not understand how to do this with the lambda function, though for simple reason that there is no name to refer back to the Lambda function. Is there any way of doing it? I can think of this as the only way to give a name to the function:
/ P>
Fact = Lambda x: 1 if x == 0 and x * fact (x-1)
Or alternatively, for earlier versions of Python:
Other using: Fact = Lambda x: x == 0 and 1 or x * fact (x-1)
update Thoughts from the answers, I was able to wipe factual function in a single anonymous lambda:
& gt; & Gt; & Gt; Map (Lambda N: (Lambda F, * A: F (F, * A)) (Lambda REC, N: 1 if N == 0 and N * REC (REC, N-1), N), Range (10
So this is possible, but not really recommended!
Comments
Post a Comment