It seems like you want to list all the possible ways to perform 3 discards from you list of items, each consisting of 3 cards. I suggest you to do a better mapping of your choices, like for example [3, 2, 0] instead of [(0,0,0),(1,0,0),(1,0,1)] where [3, 2, 0] means starting indices of your list for each discard. This case can be illustrated as follows:
[1,1,1,0,0,0,0,0,0], take out items starting from index=3
[1,1,1,0,0,0], take out items starting from index=2 ->
[1,1,0], take out items starting from index=0 ->
[]
The next step of solutions is to consider how all the possible choices of indices looks like. It's quite clear that:
- first index doesn't exceed 6 (since list has 9 items),
- second index doesn't exceed 3 (since list has 6 items)
- third index is 0 (since list has 0 items)
In general I suggest to generate all the possible choices and do discards manually for each choice:
from itertools import product
d = [1,1,1,0,0,0,0,0,0]
n = 3
starting_indices = [range(len(d)-(n-1)-n*m) for m in range(len(d)//n)]
choices = []
for idx_sequence in product(*starting_indices):
current_d = d.copy()
current_choice = []
for id in idx_sequence:
current_choice.append(current_d[id: id+n])
del current_d[id: id+n]
choices.append(current_choice)
print(choices)
Note:
Some of the choices might be duplicated
Update:
You can eliminate duplicated choices if you add these rows to your script:
choices = set([tuple(tuple(m) for m in n) for n in choices]) #if you need to remove duplicates
choices = [list(list(m) for m in n) for n in choices] #if you need to set type back
Output:
[[0, 0, 0], [1, 1, 1], [0, 0, 0]]
[[0, 0, 0], [1, 0, 0], [1, 1, 0]]
[[0, 0, 0], [1, 1, 0], [1, 0, 0]]
[[0, 0, 0], [0, 0, 0], [1, 1, 1]]
[[1, 1, 1], [0, 0, 0], [0, 0, 0]]
[[1, 0, 0], [0, 0, 0], [1, 1, 0]]
[[1, 0, 0], [1, 1, 0], [0, 0, 0]]
[[1, 1, 0], [1, 0, 0], [0, 0, 0]]
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
[[1, 1, 0], [0, 0, 0], [1, 0, 0]]