title: Combine lists to the least possible amount of 2-dimensional lists
body: <p>Sorry for the bad description in the title.</p>
  
  <p>Consider a 2-dimensional list such as this:</p>
  
  <pre><code>list = [
      [1, 2],
      [2, 3],
      [3, 4]
  ]
  </code></pre>
  
  <p>If I were to extract all possible "vertical" combinations of this list, for a total of 2*2*2=8 combinations, they would be the following sequences:</p>
  
  <pre><code>1, 2, 3
  2, 2, 3
  1, 3, 3
  2, 3, 3
  1, 2, 4
  2, 2, 4
  1, 3, 4
  2, 3, 4
  </code></pre>
  
  <p>Now, let's say I remove some of these sequences. Let's say I only want to keep sequences which have either the number 2 in position #1 OR number 4 in position #3. Then I would be left with these sequences:</p>
  
  <pre><code>2, 2, 3
  2, 3, 3
  1, 2, 4
  2, 2, 4
  1, 3, 4
  2, 3, 4
  </code></pre>
  
  <h2>The problem</h2>
  
  <p>I would like to re-combine these remaining sequences to the least possible amount of 2-dimensional lists needed to contain all sequences but no less or no more.</p>
  
  <p>By doing so, the resulting 2-dimensional lists in this particular example would be:</p>
  
  <pre><code>list_1 = [
      [2],
      [2, 3],
      [3, 4]
  ]
  list_2 = [
      [1],
      [2, 3],
      [4] 
  ]
  </code></pre>
  
  <p>In this particular case, the resulting lists can be thought out. But how would I go about if there were thousands of sequences yielding hundereds of 2-dimensional lists? I have been trying to come up with a good algorithm for two weeks now, but I am getting nowhere near a satisfying result.</p>