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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file powerset_generator-0.1.3.tar.gz.

File metadata

  • Download URL: powerset_generator-0.1.3.tar.gz
  • Upload date:
  • Size: 55.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for powerset_generator-0.1.3.tar.gz
Algorithm Hash digest
SHA256 60230a2218ecf8c25d59c0581ab8c17df7694f960f2949bd1c8a9854f0c13607
MD5 88db3a988b459e226953cd89411aa35e
BLAKE2b-256 72c1f491bb2888ecac1846efb2e5f6d3fd7716d9db13e2721a9292353f229b57

See more details on using hashes here.

File details

Details for the file powerset_generator-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for powerset_generator-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 737b37b941c64463ed216a0f640bd111866b3b85bbbe2caa37bdc14113e8ff51
MD5 2b9317a02a794b9339cd90e5e26f3bc0
BLAKE2b-256 5b787351aec2c11c9479fc7026cb7bb033ec32f14a170785079a8b264da3af97

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