logo

... lambda.


Lambda functions are just functions but typically very simple ones. It's the fact that makes them really easy to declare that makes them extremely expressive as well and in this series of videos we'd like to demonstrate not just how they work but also why they're nice to reason about.


Notes

The functools library contains many items that allow you to make the most out of lambda functions. A common example is the reduce function. We'll show a demonstration below.

from functools import reduce

numbers = [1, 2, 3, 4, 5]

# sum via reduce
reduce(lambda x, y: x + y, numbers)
# prod via reduce
reduce(lambda x, y: x * y, numbers)

Note that reduce tells us what we are doing while the lambda function tells us how we are doing it.


Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider getting the newsletter.