January 2019
Beginner
318 pages
8h 23m
English
In Python, an anonymous function is a function that is defined without a name and is called a lambda function, as it is defined using a keyword lambda. We use these functions whenever we require a function for a short period of time.
Lambda functions are used along with built-in functions, such as filter(), and map().
The filter() function returns a list of elements and has only one iterable as input. The following shows an example using filter():
numbers = [10, 25, 54, 86, 89, 11, 33, 22]new_numbers = list(filter(lambda x: (x%2 == 0) , numbers))print(new_numbers)Output:[10, 54, 86, 22]
In this example, the filter() function is taking a lambda function and a list as an argument.
The map() function returns a list of results ...
Read now
Unlock full access