Open
Description
It would be neat to have a way of iterating over all possible partitions of some vector. Example usages:
all_partitions(&vec![7,8,9])
should iterate over
[[7,8,9]]
[[7,8],[9]]
[[7,9],[8]]
[[7],[8,9]]
[[7],[8],[9]]
while partitions(&vec![6,7,8,9], 2)
should iterate over
[[6],[7,8,9]]
[[6,7],[8,9]]
[[6,8],[7,9]]
[[6,9],[7,8]]
[[6,7,8],[9]]
[[6,7,9],[8]]
[[6,8,9],[7]]
Remark: I asked this question on StackOverflow, and implemented a version of all_partitions()
. I am happy to create a PR if this is something that could belong to the itertools
package.
Metadata
Metadata
Assignees
Labels
No labels