Generate the power set of a collection
Project description
Python Power set generator
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.2.tar.gz
(55.0 kB
view hashes)
Built Distribution
Close
Hashes for powerset_generator-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dbdcde1be54b107bbd6fb0d5661d7ed459fb1572f0f844fc1175619aa30a872 |
|
MD5 | ce4bd5722d584a54c837d1de05b2ff0f |
|
BLAKE2b-256 | 2bb038e40b6fd2c7be96e60457464d3af49460dede65ba20ae1f925bbefc831c |