I am trying to make a combinations of combinations from a list of lists :)
I'll get a 2D list from my code below which returns:
[[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
this list then would be iterated to a 3D list of combinations:
[[[1], [2], [3]], [[1], [2, 3]], [[2], [1, 3]], [[3], [1, 2]], [[1, 2, 3]]]
I'm getting some progress, but the idea is a bit too mathematical for me. Any help would be appreciated :)
Thanks!
from itertools import combinations
a = [1,2,3]
temp_list = []
for i in range(0,len(a)+1):
for subset in combinations(a,i):
temp_list.append(subset)
a = temp_list
a = [list(item) for item in a]
a = list(filter(None, a))
a.sort(key=len)
a = sorted(a, key=sum)
print(a)
[[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]