title: Group Python list of lists into groups based on overlapping items
body: <p>I have a list of lists and I am trying to group or cluster them based on their items. A nested list starts a new group if none of the elements are in the previous group.</p>
  
  <p><strong>Input:</strong>  </p>
  
  <pre><code>paths = [  
          ['D', 'B', 'A', 'H'],  
          ['D', 'B', 'A', 'C'],  
          ['H', 'A', 'C'],  
          ['E', 'G', 'I'],  
          ['F', 'G', 'I']]
  </code></pre>
  
  <p><strong>My failed Code:</strong>   </p>
  
  <pre><code>paths = [
      ['D', 'B', 'A', 'H'],
      ['D', 'B', 'A', 'C'],
      ['H', 'A', 'C'],
      ['E', 'G', 'I'],
      ['F', 'G', 'I']
  ]
  groups = []
  paths_clone = paths
  for path in paths:
      for node in path:
          for path_clone in paths_clone:
              if node in path_clone:
                  if not path == path_clone:
                      groups.append([path, path_clone])
                  else:
                      groups.append(path)
  print groups
  </code></pre>
  
  <p><strong>Expected Output:</strong>  </p>
  
  <pre><code>[
   [
    ['D', 'B', 'A', 'H'],
    ['D', 'B', 'A', 'C'],
    ['H', 'A', 'C']
   ],
   [
    ['E', 'G', 'I'],
    ['F', 'G', 'I']
   ]
  ]
  </code></pre>
  
  <p><strong>Another Example:</strong>  </p>
  
  <pre><code>paths = [['shifter', 'barrel', 'barrel shifter'],
           ['ARM', 'barrel', 'barrel shifter'],
           ['IP power', 'IP', 'power'],
           ['ARM', 'barrel', 'shifter']]
  </code></pre>
  
  <p><strong>Expected Output Groups:</strong>  </p>
  
  <pre><code>output = [
           [['shifter', 'barrel', 'barrel shifter'],
           ['ARM', 'barrel', 'barrel shifter'],
           ['ARM', 'barrel', 'shifter']],
           [['IP power', 'IP', 'power']],
           ]
  </code></pre>