Let's say I have a list of 8 objects, numbered 1-8.
Objects are placed in three fields, 3 in one box, 3 in another, 2 in the last field. In mathematics, there are 8C3 * 5C3 = 560 ways to do this. I want to skip 560 elements there. Is there a way in Python to do this?
The result should look like this:
list=['12','345',678'], ['12','346','578'], ..., etc.
Please note that ['12','345','678'] and ['12','354',876'] are considered the same for this purpose.
I want to make this loop for a loop. Is there a way in Python to do this?
Here is the solution I get, but it seems ugly.
import itertools for c1,c2 in itertools.combinations(range(8),2): l2=list(range(8)) l2.pop(c2) l2.pop(c1) for c3,c4,c5 in itertools.combinations(l2,3): l3=l2[:] l3.remove(c5) l3.remove(c4) l3.remove(c3) c6,c7,c8=l3 print(c1,c2,c3,c4,c5,c6,c7,c8)