title: Python - Combinations only if condition applies
body: <p>Suppose I have a huge list of tuples:</p>
  
  <pre><code>tuples = ([1, 2], [2, 1], [3, 2], [25, 73], [1, 3]...)
  </code></pre>
  
  <p>This list has 360000 elements as of now (they are a list of coprimes numbers). I need to make combinations of 3 tuples, such that there are only 3 different numbers on each combination, example:</p>
  
  <pre><code>([2, 1], [3, 1], [3, 2])
  ([2, 1], [5, 1], [5, 2])
  </code></pre>
  
  <p>I need to discard combinations with 4 or more different numbers while generating the list of combinations.</p>
  
  <p>If I try to bruteforce this and test each combination, I end up with <code>360000 choose 3</code> which is <code>7.77 * 10^15</code>possible combinations to test.</p>
  
  <p>EDIT:
  The problem I am trying to solve is:</p>
  
  <p>Find all combinations of coprime pairs in the form:</p>
  
  <pre><code>(a, b), (a, c), (b, c)
  </code></pre>
  
  <p>for c &lt; 120000</p>
  
  <p>Steps I've taken:</p>
  
  <ol>
  <li>Generate the ternary tree for all Coprime pairs whereboth numbers are less than 120000</li>
  <li>(ISSUE - Generate the combinations, bruteforcing it won't do)</li>
  </ol>