I have a set of different numbers, e.g.
set = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110].
Now I want to partition this list into sublists which are not longer than 5.
I know how I can partition this list into sublists which are exactly 5:
partition = numpy.array_split(list, 5)
This will yield
[[10, 20, 30, 40, 50], [60, 70, 80, 90, 100], [110]].
But how can I achieve, that I have all possible partitions?
So, my “targetpartition” would contain the sets
[ [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110] ],
[ [10], [20, 30, 40, 50], [60, 70], [80, 90, 100, 110] ],
[ [10], [20], [30], [40], [50], [60], [70], [80], [90, 100], [110] ]
and many many more.
mathquester is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2