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

python list prime numbers

print([i for i in range(2, int(input("Enter your number: "))+1) if 0 not in [i%n for n in range(2, i)]])
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 :: input in one line python 
Python :: python ordered dict to dict 
Python :: print A to z vy using loop in python 
Python :: how to make gtts text to speech converter 
Python :: capitalize first letter of each word python 
Python :: turn characters to alpgabetic numper python 
Python :: decimal to octal in python 
Python :: python compare floats 
Python :: how to give a role permissions discord py 
Python :: linear search python 
Python :: change float column to percentage python 
Python :: python append csv to dataframe 
Python :: transition from python 2 to 3 terminal 
Python :: python youtube downloader 
Python :: numpy divide with exception 
Python :: strip in python 
Python :: pandas dataframe.to_dict 
Python :: python compare sets 
Python :: python openpyxl cell width 
Python :: python get current date and time 
Python :: Sum items in a list with ints and strings in python 
Python :: python word starts with 
Python :: legend text color matplotlib 
Python :: month name in python 
Python :: ffmpeg python video from images 
Python :: uppercase string python 
Python :: How To Get Redirection URL In Python 
Python :: remove prefix from string python 
Python :: face detection code 
Python :: UnicodeDecodeError: ‘utf8’ codec can’t decode byte 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =