title: Clustering items from matrix
body: <p>I have a dictionary with this format</p>
  
  <pre><code>items = {"0":'lorem ipsum', "1":'blah blah', "2":'blah", "3":'lorem',.....}
  </code></pre>
  
  <p>Let's say that <code>len(items) = 70</code></p>
  
  <p>I have a 70x70 matrix with values for each pair of the dictionary. For instance, the <code>matrix[4][20]</code> representing the value between item 4 and 20 from the dictionary.</p>
  
  <p>I want to cluster the dictionary items and put in the same group all items with a value more than a certain threshold. I don't know if my way is the best way. Maybe there is a library that can do the same thing much quicker than mine. Since my matrix could be 10000x10000.</p>
  
  <pre><code>size = range(0,len(items))
  t = 1
  mydict = {}
  for i in size:
      mylist = items[i]
      size.remove(i)
      for j in size:
          if items[j] in lis:
              pass
          elif matrix[i][j] &gt; 0.50:
              mylist.append(items[j])
              size.remove(j)
      mydict[t] = mylist
      t = t + 1
      mylist = [] 
  </code></pre>
  
  <p>And then I print all the groups with more than 5 items.</p>
  
  <pre><code>for i in mydict:
      if len(mydict[i]) &gt; 5:
          print mydict[i]
          print ""
  </code></pre>
  
  <p>Do you see any error? Do know any library or a better algorithm to do this?</p>
  
  <p><strong>UPDATED</strong>
  Here is a better example:</p>
  
  <pre><code>items = {"0": 'item 0', "1":'item 1', "2":'item 2', "3":'item 3', "4":'item 4', "5":'item 5'}
  
  matrix = [[1.0 0.2 0.7 0.8 0.3 0.1],
            [0.2 1.0 0.2 0.3 0.6 0.2],
            [0.7 0.2 1.0 0.7 0.2 0.3],
            [0.8 0.3 0.7 1.0 0.2 0.4],
            [0.3 0.6 0.2 0.2 1.0 0.1],
            [0.1 0.2 0.3 0.4 0.1 1.0]]
  
  **The results:**
  
  [item 0, item 2, item 3]
  
  [item 1, item 4]
  
  [item 5]
  </code></pre>
  
  <p>The matrix is triangular and all the points in the diagonial are 1.  </p>