Skip to main content

Set partitioning

Project description

Stirling

CI

Installation

The stirling package is available on the Python Package Index (PyPI):

PyPI version

Stirling should work with Python 3.8 or greater. To install:

$ pip install stirling

Examples

A function for generating partitions of a collection into a specific number of non-empty subsets. The number of ways of arranging a set of size n into k non-empty subsets is known at the Stirling Number of the Second Kind or S(n, k).

For example, to find the arrangements of a list of 4 integers into 3 non-empty subsets, use:

>>> from stirling import k_subsets
>>> for arrangement in k_subsets([1, 2, 3, 4], 3):
...    print(arrangement)
...
[[1, 2], [3], [4]]
[[1, 3], [2], [4]]
[[1], [2, 3], [4]]
[[1, 4], [2], [3]]
[[1], [2, 4], [3]]
[[1], [2], [3, 4]]

To determine the number of arrangements of a set of 10 items into 5 non-empty subsets, use the s2 function:

>>> from stirling import s2
>>> s2(10, 5)
42525

MIT License

Copyright (c) Robert Smallshire

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

stirling-1.2.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

stirling-1.2.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file stirling-1.2.1.tar.gz.

File metadata

  • Download URL: stirling-1.2.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for stirling-1.2.1.tar.gz
Algorithm Hash digest
SHA256 e5936a78372a117ec1b7e3580716963dcfdff3b4dcaf89a691ab40e980ed0a3e
MD5 9490beba67adaa74a8355e9c2202ef3d
BLAKE2b-256 b98436c921e774ca309202727d540297b91c9c6dbad520261a20c0fef61d64d0

See more details on using hashes here.

File details

Details for the file stirling-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: stirling-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for stirling-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 368278cfe03d306f09b76105bf45c03a375b6867a064c0e8808fa306848e53a0
MD5 1506afa37364897d8f27fb2286c25651
BLAKE2b-256 a0af5748f12d6c113c48bd6179a2d19241bae34dc64e0ca22f4f243c5fc99415

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