title: How to efficiently group pairs based on shared item?
body: <p>I have a list of pairs (tuples), for simplification something like this:</p>
  
  <pre><code>L = [("A","B"), ("B","C"), ("C","D"), ("E","F"), ("G","H"), ("H","I"), ("G","I"), ("G","J")]
  </code></pre>
  
  <p>Using python I want efficiently split this list to:</p>
  
  <pre><code>L1 = [("A","B"), ("B","C"), ("C","D")]
  L2 = [("E","F")]
  L3 = [("G","H"), ("G","I"), ("G","J"), ("H","I")]
  </code></pre>
  
  <p><strong>How to efficiently split list into groups of pairs, where for pairs in the group there must be always at least one pair which shares one item with others?</strong> As stated in one of the answers this is actually <strong>network problem</strong>. The goal is to efficiently split network into disconnected (isolated) network parts.</p>
  
  <p>Type lists, tuples (sets) may be changed for achieving higher efficiency.</p>