title: All combinations of list elements in certain order
body: <p>I have a list as follows:</p>
  
  <pre><code>((0,n1,n2,...,nX),(0,n1,n2,...,nY),(1,n1,n2,...,nZ),(2,n1,n2,...,nR),(2,n1,n2,...,nS))
  </code></pre>
  
  <p>I would like to return all possible combinations of list elements in such way:</p>
  
  <pre><code>(0,n1,n2,...,nX),(1,n1,n2,...,nZ),(2,n1,n2,...,nR)
  (0,n1,n2,...,nY),(1,n1,n2,...,nZ),(2,n1,n2,...,nR)
  (0,n1,n2,...,nX),(1,n1,n2,...,nZ),(2,n1,n2,...,nS)
  (0,n1,n2,...,nY),(1,n1,n2,...,nZ),(2,n1,n2,...,nS)
  </code></pre>
  
  <p>So, I have understood and worked out that I need to iterate through elements and check first item of the list element to group elements by first item. </p>
  
  <p>It could let me to do maybe a for loop? and try to manualy create all combinations?</p>
  
  <p>However I wonder if there is any better approach? </p>
  
  <p>I need to keep in mind that the elements must be in order ascending by first item of the elements --> 0, 1, 2</p>
  
  <p>EDIT:</p>
  
  <p>This is my list in other words:</p>
  
  <pre><code>((0,A), (0,B), (1,C), (2,D),(2,E))
  </code></pre>
  
  <p>how to return as follows:</p>
  
  <pre><code>(0,A),(1,C),(2,D)
  (0,B),(1,C),(2,D)
  (0,A),(1,C),(2,E)
  (0,B),(1,C),(2,E)
  </code></pre>
  
  <p>?</p>