Skip to main content

Python library encapsulating the set of all primes as an indexed collection (optimized for small primes).

Project description

Python library encapsulating the set of all primes as an indexed collection (optimized for small primes).

PyPI version and link.

Purpose

Native Python class that encapsulates the set of all primes as an ascending sequence. Optimizations are included for finding and generating relatively small prime numbers.

Package Installation and Usage

The package is available on PyPI:

python -m pip install primelist

The library can be imported in the usual way:

from primelist import primelist

Examples

The library provides a static class that behaves like a list-like object that virtually contains all prime numbers:

>>> 17 in primelist
True
>>> 1000000000000000000000000000 in primelist
False
>>> primelist[0]
2
>>> primelist[79905]
1019173
>>> primelist[1:6]
[3, 5, 7, 11, 13]

All prime numbers up to six digits in length are loaded into memory from disk on every one of the above queries. If an expression requires a larger range of primes to succeed, additional primes are generated as necessary in ascending order (inefficiently).

To maintain the list of primes in memory (both those loaded and those subsequently generated due to additional method invocations), it is possible to instead create an object. The object’s methods are the same as those of the class primelist:

>>> ps = primelist()
>>> 17 in ps
True
>>> 1000000000000000000000000000 in ps
False
>>> ps[0]
2
>>> ps[79905]
1019173
>>> ps[1:6]
[3, 5, 7, 11, 13]

It is possible to use the len function to obtain the number of primes that have been computed and stored so far within the object. The output below may not match exactly what you see in your environment:

>>> ps = primelist()
>>> len(ps)
78498

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

primelist-0.1.0.0.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file primelist-0.1.0.0.tar.gz.

File metadata

  • Download URL: primelist-0.1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for primelist-0.1.0.0.tar.gz
Algorithm Hash digest
SHA256 d28a03830a178702192fcd000a704d5eb2b49ccded4e2a3303dc13e80192d47b
MD5 67964997e4b6d129c4bc8905ed0cb199
BLAKE2b-256 3a4a4f7510469934ec03ce94ea49779da5effbd46823082daae84e9202e5f4e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page