-In Python, anonymous function means that a function is without a name. As we already know that def keyword is used to define the normal functions and the lambda keyword is used to create anonymous functions.
- filter() is a python function which filters the given sequence with the help of a function that tests each element in the sequence to be true or not.
Lambda with filter function-
In filter we require a function for argument, so at the place of the function, we create a lambda function which return True according to given expression.
#filter all integer value from the list
print("List after filtering")
#filter all even number from the list
print("After even filteration, list become")
list is [1, 2, 3, 4, 'one', 'two', 1.2]
List after filtering
[1, 2, 3, 4]
After even filteration, list become
-In this program, we have a list [1,2,3,4,"one",'two',1.2000] then by filter() we pass each value of the list to the lambda function then by type(x)==int return True only on integer value and other value is discard.
-then in other case we have a list [1,2,3,4] and condition in lambda is x%2==0 which return True on even value and other value are discard.