from math import sqrt def primetest(x): if x < 2 or (x > 2 and x % 2 == 0): return False d = 3 while d <= sqrt(x): if x % d == 0: return False d += 2 return True x = [i for i in range(1001) if primetest(i)] print(x)