PartitionWhile
The function PartitionWhile splits a collection into sublists comprised of consecutive elements which satisfy a given condition.
The first argument of PartitionWhile is a list to be partitioned. The second argument is a boolean function which determines the condition which the partitions must satisfy. The resulting sublists are such that this function evaluates to True on each of them.
For example:
from partition_while import PartitionWhile
print(PartitionWhile([1,2,3,4,5,6,7,8,9,10], lambda x: sum(x) <= 10))
# [[1, 2, 3, 4], [5], [6], [7], [8], [9], [10]]
In detail, the algorithm of PartitionWhile implements a double loop for each element of the list and its successive elements. The first subpartition is built by starting to add the list elements after the function first evaluates to True until the function evaluates to False on some successive element. Then the second subpartition is searched in the same way, starting from this last element and the program continues until the end of the list.
PartitionWhile accepts the following option:
- shortest (= True): change the length of the partitions
Different partitions, always satisfying the given condition, can be determined through different values for this option:
- True : split always at the Shortest partition
- False : search always the Longest partition
- k : search k-1 next elements after the shortest partition
For example:
print(PartitionWhile([-5,8,1,2,6,-20,8,9,-5,7,3], lambda x: sum(x) <= 10))
#[[-5, 8, 1, 2], [6, -20, 8, 9, -5, 10]]
print(PartitionWhile([-5,8,1,2,6,-20,8,9,-5,7,3], lambda x: sum(x) <= 10,shortest=False))
#[[-5, 8, 1, 2, 6, -20, 8, 9, -5], [7, 3]]
More details and examples are given in the documentation for the homonymous resource function on the Wolfram Function Repository.
Metadata
Release files for partition-while 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| partition_while-1.0.0.tar.gz | 2.4 kB | Without provenance | Details for partition_while-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| partition_while-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for partition_while-1.0.0-py3-none-any.whl |
Total release size: 5.1 kB
Release files / partition_while-1.0.0.tar.gz
| Download URL | partition_while-1.0.0.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ddea7d2867f527e00be93636bce7f8b47f2e4d236465a0ceb37416b56131ac0
|
|
BLAKE2b-256 checksum How to use checksums |
1397f19d0fb354928dc9a27a500c03c2b9f7e26c31575b41204465d057bba1fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.3
|
Release files / partition_while-1.0.0-py3-none-any.whl
| Download URL | partition_while-1.0.0-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33cd12290a98ff8ba7f3e1cf6d2123628291346c0f3d4fd4e93d92599b9a88e1
|
|
BLAKE2b-256 checksum How to use checksums |
60d4c8bb0d6dfe33229401bb091e5826da03aff8ac6615438dfd77e5624a1556
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.3
|
Security for partition-while 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.