Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

list of prime numbers in python with list comprehension

n = 20

primes = [i for i in range(2, n + 1) if all(i%j != 0 for j in range(2, int(i ** 0.5) + 1))]

print(primes)
Comment

how to get prime numbers in a list in python using list comprehension

>>> [x for x in range(2, 20)
     if all(x % y != 0 for y in range(2, x))]
[2, 3, 5, 7, 11, 13, 17, 19]
Comment

PREVIOUS NEXT
Code Example
Python :: convert x unicode utf 8 bytes to u python 
Python :: python read html table 
Python :: return max repeated value in list 
Python :: exec to return a value python 
Python :: pil image to numpy array 
Python :: 2d array pytho 
Python :: groupby year datetime pandas 
Python :: instagram login with selenium py 
Python :: how to uninstall python idle on ubuntu 
Python :: lock in python 
Python :: make sure text is on page selenium python 
Python :: simple time in python 
Python :: multiple functions tkinter 
Python :: how to create a label in tkinter 
Python :: replace nat with date pandas 
Python :: Get List Into String 
Python :: declare numpy zeros matrix python 
Python :: python procedured 
Python :: replace values of pandas column 
Python :: colored text in py 
Python :: how to round a number down in python 
Python :: python absolute value 
Python :: how to add column to np array 
Python :: find record where dataframe column value contains 
Python :: create text file in directory python linux 
Python :: pytorch l2 regularization 
Python :: starting vscode on colab 
Python :: what is python used for 
Python :: pygame music player 
Python :: python currency signs 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =