Use of python filter function

Author: Al-mamun Sarkar Date: 2020-03-25 09:00:35

Use function with filter. Filtering list using filter function in the python programming language. 

my_list = [2, 3, 4, 5, 6, 7]


def is_even(x):
    if (x % 2) == 0:
        return True
    else:
        return False


new_list = filter(is_even, my_list)
print(new_list)
print(list(new_list))

 

Output:


[2, 4, 6]