- filter() is a python function which 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,sequence)
-Here we find the all prime number from the list with using of filter() function.
program-
print("Enter the number in the list")
l=list(map(int,input().split()))
print("List is ",l)
def findprime(n):
for i in range(2,int(n/2)+1):
if n%i==0:
return False
return True
#second way
l=filter(findprime,l )
print("prime number are:",*l)
Enter the number in the list
1 2 3 4 5 6 7 11 15 19
List is [1,2,3,4,5,6,7,11,15,19]
prime number are: 1 2 3 5 7 11 19