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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad8fd610aff8fab5e967964a44650a2164eab2f247a9fb302fcda710eb257720
|
|
| MD5 |
d8706b510116d5f02e84346da18e602a
|
|
| BLAKE2b-256 |
9db9e2d159a6af15fc6378334d04cb8db68c256d3ca7b3448bdfa3fa2c52bbc8
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf391567dc0eacab0df69f8077cf42332bbe060c57171b3124b7df67770e1b15
|
|
| MD5 |
fd82f9387eababa7acedddede46ccc94
|
|
| BLAKE2b-256 |
bc24478b74febdb49aca88c7fa67a2b1f8d7b01be8d946b4e32b07c633038550
|