Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Partition a list into roughly equal lengths
partitions list into n nonoverlapping sublists of near-equal length.
When the length of list is divisible by the number of partitions n, all the returned lists will be equal in length. In other cases, ResourceFunction["NearEqualPartition"] maximizes the length of the smallest partition.
Partition a list into three non-overlapping sublists:
When the list cannot be partitioned in equal lengths, the first sublists are the longest:
When the length of the list is divisible by the partition count, all lists are the same length:
No elements of the input are discarded and no extra elements introduced, so for a one-dimensional list the inverse operation is Flatten:
The lengths of the sublists should not differ by more than 1:
This work is licensed under a Creative Commons Attribution 4.0 International License