+ 1
Can someone explain this code to me?
3 Answers
+ 2
Havenât really programmed in a while, but by playing around with the code I got the following:
1. The m() is your lambda function
2. The iteration in the lambda is a range of 3 (0,1,2), so by passing m(1) it returns 2, since 0*1 = 0, 1*1 = 1, and 2*1 = 2, which is the final value that the method returns.
3. Its printing â2â three times because the cm() method returns a lambda function that runs 3 times.
4. In a sense you could see it as a nested loop, where the lambdaâs functionâs for loop is nested inside the âfor m in cm()â
Again, this is my interpretation of the code. Hope this helps!
+ 2
Matias Dure your interpretation is correct.
Radouane using a lambda function like that kind of defeats its purpose. Their main advantage is not having to define a normal function. So defining a normal function that does nothing but return a lambda function is redundant.
0
Thanks, I think I understand.