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.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

komby-1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for komby-1.2.tar.gz
Algorithm Hash digest
SHA256 ad8fd610aff8fab5e967964a44650a2164eab2f247a9fb302fcda710eb257720
MD5 d8706b510116d5f02e84346da18e602a
BLAKE2b-256 9db9e2d159a6af15fc6378334d04cb8db68c256d3ca7b3448bdfa3fa2c52bbc8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: komby-1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf391567dc0eacab0df69f8077cf42332bbe060c57171b3124b7df67770e1b15
MD5 fd82f9387eababa7acedddede46ccc94
BLAKE2b-256 bc24478b74febdb49aca88c7fa67a2b1f8d7b01be8d946b4e32b07c633038550

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