lst = [2, 2, 2, 3, 5, 7]
I want to partition it into two or more sets. Here is my code
import more_itertools as mit
import pprint as pp
from operator import itemgetter
from itertools import groupby
x = [part for k in range(1, len(lst) + 1) for part in mit.set_partitions(lst, k)]
x.sort()
x = list(map(itemgetter(0), groupby(x)))
pp.pprint(x)
Here is my current output:
[[[2], [2], [2], [3], [5], [7]],
[[2], [2], [2], [3], [5, 7]],
[[2], [2], [2], [3, 5], [7]],
[[2], [2], [2], [3, 5, 7]],
[[2], [2], [2], [5], [3, 7]],
[[2], [2], [2, 3], [5], [7]],
[[2], [2], [2, 3], [5, 7]],
[[2], [2], [2, 3, 5], [7]],
[[2], [2], [2, 3, 5, 7]],
[[2], [2], [2, 5], [3, 7]],
[[2], [2], [3], [2, 5], [7]],
[[2], [2], [3], [2, 5, 7]],
[[2], [2], [3], [5], [2, 7]],
[[2], [2], [3, 5], [2, 7]],
[[2], [2], [5], [2, 3, 7]],
[[2], [2, 2], [3], [5], [7]],
[[2], [2, 2], [3], [5, 7]],
[[2], [2, 2], [3, 5], [7]],
[[2], [2, 2], [3, 5, 7]],
[[2], [2, 2], [5], [3, 7]],
[[2], [2, 2, 3], [5], [7]],
[[2], [2, 2, 3], [5, 7]],
[[2], [2, 2, 3, 5], [7]],
[[2], [2, 2, 3, 5, 7]],
[[2], [2, 2, 5], [3, 7]],
[[2], [2, 3], [2, 5], [7]],
[[2], [2, 3], [2, 5, 7]],
[[2], [2, 3], [5], [2, 7]],
[[2], [2, 3, 5], [2, 7]],
[[2], [2, 5], [2, 3, 7]],
[[2], [3], [2, 2, 5], [7]],
[[2], [3], [2, 2, 5, 7]],
[[2], [3], [2, 5], [2, 7]],
[[2], [3], [5], [2, 2, 7]],
[[2], [3, 5], [2, 2, 7]],
[[2], [5], [2, 2, 3, 7]],
[[2, 2], [2], [3], [5], [7]],
[[2, 2], [2], [3], [5, 7]],
[[2, 2], [2], [3, 5], [7]],
[[2, 2], [2], [3, 5, 7]],
[[2, 2], [2], [5], [3, 7]],
[[2, 2], [2, 3], [5], [7]],
[[2, 2], [2, 3], [5, 7]],
[[2, 2], [2, 3, 5], [7]],
[[2, 2], [2, 3, 5, 7]],
[[2, 2], [2, 5], [3, 7]],
[[2, 2], [3], [2, 5], [7]],
[[2, 2], [3], [2, 5, 7]],
[[2, 2], [3], [5], [2, 7]],
[[2, 2], [3, 5], [2, 7]],
[[2, 2], [5], [2, 3, 7]],
[[2, 2, 2], [3], [5], [7]],
[[2, 2, 2], [3], [5, 7]],
[[2, 2, 2], [3, 5], [7]],
[[2, 2, 2], [3, 5, 7]],
[[2, 2, 2], [5], [3, 7]],
[[2, 2, 2, 3], [5], [7]],
[[2, 2, 2, 3], [5, 7]],
[[2, 2, 2, 3, 5], [7]],
[[2, 2, 2, 3, 5, 7]],
[[2, 2, 2, 5], [3, 7]],
[[2, 2, 3], [2, 5], [7]],
[[2, 2, 3], [2, 5, 7]],
[[2, 2, 3], [5], [2, 7]],
[[2, 2, 3, 5], [2, 7]],
[[2, 2, 5], [2, 3, 7]],
[[2, 3], [2, 2, 5], [7]],
[[2, 3], [2, 2, 5, 7]],
[[2, 3], [2, 5], [2, 7]],
[[2, 3], [5], [2, 2, 7]],
[[2, 3, 5], [2, 2, 7]],
[[2, 5], [2, 2, 3, 7]],
[[3], [2, 2, 2, 5], [7]],
[[3], [2, 2, 2, 5, 7]],
[[3], [2, 2, 5], [2, 7]],
[[3], [2, 5], [2, 2, 7]],
[[3], [5], [2, 2, 2, 7]],
[[3, 5], [2, 2, 2, 7]],
[[5], [2, 2, 2, 3, 7]]]
I have managed to remove some amount of redundancy by sorting followed by using groupby(x)
as you can see but there are more redundancies like
[[2], [2, 2], [3], [5], [7]]
and
[[2, 2], [2], [3], [5], [7]]
for me are one and the same thing since order is not important to me.
Please dont close the question without putting in an effort. I have framed the question only after going through other similar questions on stackoverflow, they are for ordered sets, mine is for unordered sets.(part of my code were formed from those answers)