Skip to content

Feature Request: partitions #611

Open
@bruderjakob17

Description

@bruderjakob17

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions