Lets assume I have an array arr = ['a', 'b', 'c', 'd', 'e']
. I want to get a list of all the ways I can split this into x groups.
For instance, if I do:
get_all_ways_to_split_array_into_x_groups(arr, 2)
should return something like:
[
(['a'], ['b', 'c', 'd', 'e']),
(['a', 'b'], ['c', 'd', 'e']),
(['a', 'b', 'c'], ['d', 'e']),
(['a', 'b', 'c', 'd'], ['e']),
(['b'], ['a', 'c', 'd', 'e']),
...
]
Where the order of the groups and the order of the elements in each group does not matter. I've looked at numpy/scipy/itertools/etc and cannot find something like this so I suspect custom code will be required and this could be quite computationally expensive. Any suggestions?
Edit: The initial array is not large, max of 20 or so elements.