title: How do I iterate through combinations of a list
body: <p>I have a list of elements, say </p>
  
  <pre><code>list = [1, 2, 3, 4]
  </code></pre>
  
  <p>and I would like to iterate through couples of distinct elements of this list, so</p>
  
  <pre><code>for x, y in some_iterator(list):
      print x, y
  </code></pre>
  
  <p>should show</p>
  
  <pre><code>1 2
  1 3
  1 4
  2 3
  2 4
  3 4
  </code></pre>
  
  <p>Note that I don't want all combinations of <code>list</code> as in <a href="https://stackoverflow.com/q/8371887/3128109">this question</a>. Just the combinations of a given length.</p>
  
  <p>What would be the most pythonic way of doing this ?</p>
  
  <hr>
  
  <p>What if I wanted to do the same with n-uples ? For instance with combinations of <code>3</code> elements out of <code>n</code></p>
  
  <pre><code>for x, y, z in another_iterator(list):
      print x, y, z
  </code></pre>
  
  <p>would show</p>
  
  <pre><code>1 2 3
  1 2 4
  2 3 4
  </code></pre>