Find all prime number in the list in python by R4R Team

- 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)


output-

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


-In this program, we take an input of list , then using findprime() we identify that prime number and filter() function seprate prime number and print them.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!