Probably the quickest way to have primary numbers is the following:
import sympylist(sympy.primerange(lower, upper+1))
In case you don't need to store them, just use the code above without conversion to the list
. sympy.primerange
is a generator, so it does not consume memory.