dividing range by combinations
The following is an example:
temp = range(5)
L = [2,1,2]
Then we know that
5C2×3C1×2C2=30
We can get every combinations as following:
result = []
for A in Combinations(temp, L[0]):
temp = list(set(temp) - set(A))
for B in Combinations(temp, L[1]):
temp = list(set(temp) - set(B))
result += [[A,B, temp]]
temp = list(set(range(5))- set(A))
temp = range(5)
Then result
is
[[[0, 1], [2], [3, 4]], [[0, 1], [3], [2, 4]], [[0, 1], [4], [2, 3]], [[0, 2], [1], [3, 4]], [[0, 2], [3], [1, 4]], [[0, 2], [4], [1, 3]], [[0, 3], [1], [2, 4]], [[0, 3], [2], [1, 4]], [[0, 3], [4], [1, 2]], [[0, 4], [1], [2, 3]], [[0, 4], [2], [1, 3]], [[0, 4], [3], [1, 2]], [[1, 2], [0], [3, 4]], [[1, 2], [3], [0, 4]], [[1, 2], [4], [0, 3]], [[1, 3], [0], [2, 4]], [[1, 3], [2], [0, 4]], [[1, 3], [4], [0, 2]], [[1, 4], [0], [2, 3]], [[1, 4], [2], [0, 3]], [[1, 4], [3], [0, 2]], [[2, 3], [0], [1, 4]], [[2, 3], [1], [0, 4]], [[2, 3], [4], [0, 1]], [[2, 4], [0], [1, 3]], [[2, 4], [1], [0, 3]], [[2, 4], [3], [0, 1]], [[3, 4], [0], [1, 2]], [[3, 4], [1], [0, 2]],[[3, 4], [2], [0, 1]]]
The problem is that 'How can I get the general case?'
temp = range(k)
L = [e1, e2, ⋯, en ], where ∑ni=1ei=k
I don't know the size of list L.