Skip to main content

Generate the power set of a collection

Project description

Python Power set generator

Checked with mypy Ruff Hatch project Documentation PyPi


Installation

pip install powerset-generator

Example

import powerset_generator

for e in powerset_generator.subsets(["one", "two", "three", "three"]):
    print(e)

produces

set()
{'one'}
{'three'}
{'two'}
{'one', 'three'}
{'one', 'two'}
{'three', 'two'}
{'one', 'three', 'two'}

Note that the empty set, set() is included in the output and that the function treats the duplicated input element "three" as if it appeared only once. This is correct behavior the mathematical notion of power set.

See the more complete (perhaps excessively so) documentation for more details.

Credit

The code for the subsets() function is derived heavily from Allen Downey's Stack Overflow answer.

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

powerset_generator-0.1.3.tar.gz (55.1 kB view hashes)

Uploaded Source

Built Distribution

powerset_generator-0.1.3-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

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