title: Python looping combinations of 8 objects into 3 groups, 3-3-2
body: <p>Let's say I have a list of 8 objects, numbered that 1-8.</p>
  
  <p>The objects are put into three boxes, 3 in one box, 3 in another box, 2 in the last box. By mathematics, there are 8C3*5C3=560 ways to do this. I want to loop through there 560 items.
  Is there any way in Python to do so?</p>
  
  <p>The result should look like this:</p>
  
  <pre><code>list=['12','345',678'], ['12','346','578'], ..., etc.
  </code></pre>
  
  <p>Note that <code>['12','345','678']</code> and <code>['12','354',876']</code> are considered the same for this purpose.</p>
  
  <p>I want to make a for-loop this list. Is there any way in Python to do so?</p>
  
  <p>Here is the solution I get, but it seems ugly.</p>
  
  <pre><code>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)
  </code></pre>