Skip to main content

Finding all the possible partitions of a list.

Project description

komby

The Problem

Finding all the possible partitions of a list maintaining in the partition the order of the elements in the original list, and all the elements in the original list must be in some partition.

A list with 3 elements, for example [1, 2, 3], will produce 2n-1 = 4 possible partitions:

1 - [[1, 2, 3]]
2 - [[1, 2], [3]]
3 - [[1], [2, 3]]
4 - [[1], [2], [3]]

Usage

Code:

    import Komby

    data = [1, 2, 3]

    print("Number of possible partitions: {}.\n".format(Komby.total_partitions(data)))

    partitions = Komby.partitions(data, True)

    print("Partitions:")
    for p in partitions:
        print("\t - {}".format(p))

Output:

Number of possible partitions: 4.

Partitions:
	 - [[1, 2, 3]]
	 - [[1, 2], [3]]
	 - [[1], [2, 3]]
	 - [[1], [2], [3]]

Install

You can install Komby easily via pip:

pip install -U komby

Tests

Tests

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

komby-1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

komby-1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file komby-1.1.tar.gz.

File metadata

  • Download URL: komby-1.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for komby-1.1.tar.gz
Algorithm Hash digest
SHA256 a11e69397d0b2e19956868b866c95c39d9c6e11825a3b5890006647c911bfb1e
MD5 d4ff79d89fe8e1649e9995949d2751f5
BLAKE2b-256 390bf26cb472e683ff0dac602106bbdf9052f010d0c4957821a9b06fb7c7dbb9

See more details on using hashes here.

File details

Details for the file komby-1.1-py3-none-any.whl.

File metadata

  • Download URL: komby-1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for komby-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2fe655f404e16153f9402cafd985e8fc73ab25c7b72b0ecd1429f2d3f366a7f
MD5 ff4a3defb1e14b256eeee185181e40fb
BLAKE2b-256 6429784506e266cf4deaaebb1a3777169aa98266ecea5b9a8c955979a7b8a747

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