title: python combinations of multiple list
body: <p>Is there any pythonic method to generate combinations between multiple list? (similar to Cartesian product but more complicated)</p>
  
  <p>Example:</p>
  
  <pre><code>a = [1, 2, 3]
  b = [4, 5, 6]
  c = [7, 8, 9]
  # ...
  # there are more than 3 lists
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>1. [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
  2. [(1, 4, 8), (2, 5, 7), (3, 6, 9)]
  3. [(1, 4, 9), (2, 5, 7), (3, 6, 8)]
  4. [(1, 5, 7), (2, 4, 8), (3, 6, 9)]
  5. ...
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Thanks for the quick reply~!!</p>
  
  <p>To clarify the question:</p>
  
  <p>The result are all non-repeated combinations of Cartesian product of list a, b, c.</p>
  
  <p>It can be done by another ugly method:</p>
  
  <p>1) Generate the whole list of Cartesian product</p>
  
  <pre><code>from itertools import product, combinations, chain
  t = list(product(a, b, c))
  </code></pre>
  
  <p>2) Using combinations to generate all possible results</p>
  
  <pre><code>p = list(combinations(t, 3))
  </code></pre>
  
  <p>3) Filter the repeated conditions</p>
  
  <pre><code>cnt = len(list(chain(a, b, c)))
  f = [x for x in p if len(set(chain(*x))) == cnt]
  </code></pre>
  
  <p><strong>Update2:</strong></p>
  
  <p>Expected result generated by ugly method:</p>
  
  <pre><code>((1, 4, 7), (2, 5, 8), (3, 6, 9))
  ((1, 4, 7), (2, 5, 9), (3, 6, 8))
  ((1, 4, 7), (2, 6, 8), (3, 5, 9))
  ((1, 4, 7), (2, 6, 9), (3, 5, 8))
  ((1, 4, 8), (2, 5, 7), (3, 6, 9))
  ((1, 4, 8), (2, 5, 9), (3, 6, 7))
  ((1, 4, 8), (2, 6, 7), (3, 5, 9))
  ((1, 4, 8), (2, 6, 9), (3, 5, 7))
  ((1, 4, 9), (2, 5, 7), (3, 6, 8))
  ((1, 4, 9), (2, 5, 8), (3, 6, 7))
  ((1, 4, 9), (2, 6, 7), (3, 5, 8))
  ((1, 4, 9), (2, 6, 8), (3, 5, 7))
  ((1, 5, 7), (2, 4, 8), (3, 6, 9))
  ((1, 5, 7), (2, 4, 9), (3, 6, 8))
  ((1, 5, 7), (2, 6, 8), (3, 4, 9))
  ((1, 5, 7), (2, 6, 9), (3, 4, 8))
  ((1, 5, 8), (2, 4, 7), (3, 6, 9))
  ((1, 5, 8), (2, 4, 9), (3, 6, 7))
  ((1, 5, 8), (2, 6, 7), (3, 4, 9))
  ((1, 5, 8), (2, 6, 9), (3, 4, 7))
  ((1, 5, 9), (2, 4, 7), (3, 6, 8))
  ((1, 5, 9), (2, 4, 8), (3, 6, 7))
  ((1, 5, 9), (2, 6, 7), (3, 4, 8))
  ((1, 5, 9), (2, 6, 8), (3, 4, 7))
  ((1, 6, 7), (2, 4, 8), (3, 5, 9))
  ((1, 6, 7), (2, 4, 9), (3, 5, 8))
  ((1, 6, 7), (2, 5, 8), (3, 4, 9))
  ((1, 6, 7), (2, 5, 9), (3, 4, 8))
  ((1, 6, 8), (2, 4, 7), (3, 5, 9))
  ((1, 6, 8), (2, 4, 9), (3, 5, 7))
  ((1, 6, 8), (2, 5, 7), (3, 4, 9))
  ((1, 6, 8), (2, 5, 9), (3, 4, 7))
  ((1, 6, 9), (2, 4, 7), (3, 5, 8))
  ((1, 6, 9), (2, 4, 8), (3, 5, 7))
  ((1, 6, 9), (2, 5, 7), (3, 4, 8))
  ((1, 6, 9), (2, 5, 8), (3, 4, 7))
  </code></pre>