Python program that performs the filtering task