Lambda functions

A lambda function is a small anonymous function defined in a single expression with lambda. It is mostly used as a short argument, for example for the key of sorted. As soon as the logic gets long, a named def function is preferable.

Example

sorted(mots, key=lambda m: len(m))

Related concepts

The whole glossary