python fillter code example

Example 1: python filter

number_list = range(-5, 5)
less_than_zero = list(filter(lambda x: x < 0, number_list))
print(less_than_zero)

# Output: [-5, -4, -3, -2, -1]

Example 2: what are filters in python

In simple words, the filter() method filters the given iterable 
with the help of a function that tests
each element in the iterable to be true or not.

Filter Methods is simply a like comprarator class of c++ STL


Code Explanation: 
  # A simple tutorial to show the filter 
# methods in python

grades = ['A','B','C','F']

def remove_fails(grades):
    return grades!='F'

print(list(filter(remove_fails,grades)))