Python OOPs


Python SQLite


Examples


Others


Python Filter Function


The filter() function filters the given sequence with the help of a function that tests each element in the sequence to be true or not.

Syntax
filter(function, iterable)

Write a Python program to print the even numbers of a given list using filter.

Example
a=[1,2,3,4,5]
def even(a):
    if a%2==0:
        return True
    else:
        return False
        
b=list(filter(even,a))
print(b)
Output
[2, 4]