lambda is a computer science construct for creating an undeclared, unnamed function. I think I first saw it in lisp.
saying:
Code:
x=lambda a: a + 1
is the same as:
Code:
def x( a ):
return a + 1
Notice that lambda has the effect of implicitly returning the result of its last operation.
reduce takes members of a list and successively (not recursively) applies a function to each member of the list accumulating the result. From the manual:
So, to understand the last example, just remember that + is the string concatenation operator and a string is a list that reduce will iterate over.
Note that I *never* use lambdas in my code, you never remember what you were trying to do when your debugging the code 6 months later. It really only exists to make you look cool.
I've seen lambda and reduce before, in Lisp. My problem was not realizing that + was concatenation rather than addition and that a string was a list. (I fooled around with Python a while back, then let it drop.) I get it now. Thanks!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.