Use of python filter function

Use of python filter function

Instructor-svgAl-Mamun Sarkar
Mar 25 , 2020

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]

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram