Python Lambda Functions
Python Lambda function is known as the anonymous function that is defined without a name. Python allows us to not declare the function in the standard manner, i.e., by using the def keyword. Rather, the anonymous functions are declared by using the lambda keyword. However, Lambda functions can accept any number of arguments, but they can return only one value in the form of expression.
The anonymous function contains a small piece of code. It simulates inline functions of C and C++, but it is not exactly an inline function.
Use lambda function with filter()
The Python built-in filter() function accepts a function and a list as an argument. It provides an effective way to filter out all elements of the sequence. It returns the new sequence in which the function evaluates to True.
Using lambda function with map()
The map() function in Python accepts a function and a list. It gives a new list which contains all modified items returned by the function for each item.
0 Comments