Skip to main content

Consolidation of existing third party recipes for partitioning of sets and multisets/bags.

Project description

Partition Sets provides a consolidated set of recipes gently provided by other users over the years and under the MIT license. I modified these slightly so that they now equally work under python2 and python3. All bugs are mine ;-)

You may find it useful for tasks involving small sets and also multi sets/bags.

Install

A simple pip install PartitionSets should suffice.

Usage

Typical usage in python code might look like this:

#!/usr/bin/env python

from __future__ import print_function
from partitionsets import ordered_set
from partitionsets import partition

a_list = 'red green yellow blue'.split(" ")
an_oset = ordered_set.OrderedSet(a_list)
a_partition = partition.Partition(ordered_set)
for a_part in a_partition:
    print (a_part)

The sript partition_sets.py inside the bin folder may offer useful commands. For usage info run it with the -h help option:

$> partition_sets.py -h
usage: partition_sets.py [-h] [-q | -v] [-o OUT_FILENAME] [-T {text,csv,json}]
                         [-b] [-m]
                         element [element ...]

partitioning of small sets with 25 or less members

positional arguments:
  element               define set as list of elements separated by spaces

optional arguments:
  -h, --help            show this help message and exit
  -q, --quiet
  -v, --verbosity       increase output verbosity
  -o OUT_FILENAME, --out-filename OUT_FILENAME
                        out file name if specified, else all sent to stdout
  -T {text,csv,json}, --type {text,csv,json}
                        type of output (format), defaults to text
  -b, --bell-numbers    export the Bell numbers known by package
  -m, --multi-set       handle elements as being par tof a multiset or bag

Notes

Note this implementation works only for sets with 25 members or less.

This constraint is considered quite reasonable, as the method (constructing an integer index) for larger numbers starts to overflow. Remember: The number of partitions very steeply rises with each additional member considerably …

Thanks also to

This package merely wraps up several recipes (and comments) gently provided under the MIT license through several people. Those I noticed have been noted below. Any missing names are my fault. In case I get notified, I will try to update, add or remove items in below lists accordingly.

Partition

  • Anton Vredegoor

  • Chris Haulk

OrderedSet

  • Don Sawatzky

  • Emil Wall

  • Raymond Hettinger

Misc

For further reference please see the comments of the module files.

References

[A0001101]: “Bell or exponential numbers: ways of placing n labeled balls

into n indistinguishable boxes.” at http://oeis.org/A000110

[BellNumber]: Wikipedia entry Bell_number

at http://en.wikipedia.org/wiki/Bell_number

[OEIS]: Wikipedia entry On-Line_Encyclopedia_of_Integer_Sequences at

http://en.wikipedia.org/wiki/On-Line_Encyclopedia_of_Integer_Sequences

[Flake8]: https://pypi.python.org/pypi/flake8

[OrdSetImplPy]: http://code.activestate.com/recipes/576694/ (mixed with

the simplified code from Don Sawatzky’s comment, which is sufficient for this task)

[PartImplPy]: http://code.activestate.com/recipes/577211/ (r1)

[PartOfASet_WP]: Wikipedia entry Partition_of_a_set at

http://en.wikipedia.org/wiki/Partition_of_a_set

[PyLint]: https://pypi.python.org/pypi/pylint

Project details


Download files

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

Source Distributions

PartitionSets-0.1.1.zip (15.3 kB view details)

Uploaded Source

PartitionSets-0.1.1.tar.gz (8.8 kB view details)

Uploaded Source

PartitionSets-0.1.1.tar.bz2 (8.9 kB view details)

Uploaded Source

File details

Details for the file PartitionSets-0.1.1.zip.

File metadata

  • Download URL: PartitionSets-0.1.1.zip
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PartitionSets-0.1.1.zip
Algorithm Hash digest
SHA256 a2eb6f398aad4523230c8d7bb48d4649491661e51edb817673d5d370ccfa47e0
MD5 0eeeae86b5b6e681eeb44a3518809fbf
BLAKE2b-256 992e2bcb119ddf834c090e92de37125ad66cb61ef742a3bb05819afcc0be8110

See more details on using hashes here.

File details

Details for the file PartitionSets-0.1.1.tar.gz.

File metadata

  • Download URL: PartitionSets-0.1.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PartitionSets-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f73cd61f258dfd59ee36712824e0f153fb306e5618b86b8bf96938119590e10c
MD5 c3db274c59a856972d32bd3603d5c7d2
BLAKE2b-256 aea19fd208c60cc8ab07b44b06c9a1867b6be38e9619e4c233400b80b209435e

See more details on using hashes here.

File details

Details for the file PartitionSets-0.1.1.tar.bz2.

File metadata

File hashes

Hashes for PartitionSets-0.1.1.tar.bz2
Algorithm Hash digest
SHA256 51f0da7c46abb5ffbd27ab3abd6504ceb14c8232ca4cb9bdba98775de59fd59f
MD5 8e587128b6c4771124a22587d57463d2
BLAKE2b-256 7a144088a186280fff0deaee774fc5b2ef6c745278137b7b110a7c697b929838

See more details on using hashes here.

Supported by

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