Search⌘ K

Lambda Expression, Map and Filter

Explore how to create anonymous lambda functions and use them with map and filter to manipulate lists and sequences. This lesson helps you understand concise ways to apply functions to elements for data transformation and filtering, essential for Python data handling.

Lambda expression

Now that we know the basics of functions, we can move on and learn about the lambda expression. We’ll be using lambda expressions extensively in our pandas library.

  • A lambda expression can be used to create a small anonymous function, that is, a function without any name.
  • These throw-away functions are created where we need them.
  • Lambda expressions are mainly used in combination with the filter() and map() built-in functions.

The general syntax of a lambda expression is:

lambda argument_list: expression

In the syntax above, argument_list consists of a comma-separated list of arguments and expression ...