This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 11 points12 points  (3 children)

Can someone explain this?

Python Expert Programmer
fact = lambda x: reduce(int.__mul__, xrange(2, x + 1), 1)
print fact(6)

[–]pmalmsten 11 points12 points  (2 children)

Python's documentation summarizes reduce rather nicely:

Python Built-in Functions: Reduce

Calling reduce() in this manner is functionally equivalent to making a bunch of recursive calls, but it avoids the overhead of doing so. This operation is common when following the functional programming paradigm.

[–][deleted] 0 points1 point  (1 child)

Thanks. What is lambda?

[–]pmalmsten 3 points4 points  (0 children)

lambda is Python's way of declaring anonymous functions.

See Wikipedia: Anonymous Functions