Skip to content
Advertisement

Is there a Python library to list primes?

Is there a library function that can enumerate the prime numbers (in sequence) in Python?

I found this question Fastest way to list all primes below N but I’d rather use someone else’s reliable library than roll my own. I’d be happy to do import math; for n in math.primes:

Advertisement

Answer

Since asking this question, I wrote a Python wrapper around the C++ library primesieve, which went on to be adopted by the primesieve maintainer. https://github.com/kimwalisch/primesieve-python

Install from PyPi https://pypi.org/project/primesieve/ pip install primesieve

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement