Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from math import sqrt
- limit=int(input("Prime numbers upto: "))
- y=[] #This list will contain prime numbers
- #Generating a list of all numbers upto entered limits
- x=np.arange(1,limit+1)
- #Lambda function takes x and returns
- #True if the list containing multiples of passed x is 0.
- #Here, I have used list comprehension to do so.
- prime=lambda x: len([i for i in range(2,int(sqrt(x)+1)) if (x%i)==0])==0
- #Filter out numbers from array x and print them as list
- y=list(filter(prime,x))
- print(y)
Advertisement