title: Python cosine-similarity on all possible pairs in list
body: <p>I'm learning Python slowly and was wondering if I could have some help.  I have a list of ips, occurrence_id and vector called <em>info_list</em>:</p>
  
  <pre><code>('188.74.64.243', '1', ['0, 1, 1, 0'])
  ('99.229.98.18',  '1', ['0, 1, 1, 1'])
  ('86.41.253.102', '1', ['1, 1, 1, 1'])
  ('188.74.64.243', '2', ['0, 1, 1, 0'])
  ('99.229.98.18',  '2', ['0, 1, 1, 1'])
  ('86.41.253.102', '2', ['1, 1, 1, 1'])
  </code></pre>
  
  <p>I want to calculate cosine similarity.  I have the following:</p>
  
  <pre><code>def cosine_similarity(v1,v2):
      sumxx, sumxy, sumyy = 0, 0, 0
      for i in range(len(v1)):
          x = v1[i]; y = v2[i]
          sumxx += x*x
          sumyy += y*y
          sumxy += x*y
      return sumxy/math.sqrt(sumxx*sumyy)
  
  v1 = [0, 1, 1, 0]
  v2 = [1, 1, 1, 1]
  print(v1, v2, cosine_similarity(v1,v2))
  </code></pre>
  
  <p>This works great when <em>v1</em> and <em>v2</em> are stated.  My problem is that I'm in a little bit of a loop hole and can't seem to piece together my problem.  I was hoping for a little help.</p>
  
  <p>I need to loop through <em>info_list</em>, taking into consideration each pair of <em>ips</em> that have the same <em>occurrence_id</em> to calculate the <em>cosine_similarity</em>.</p>
  
  <p>An example of the output would be a list like so:</p>
  
  <pre><code>    ('188.74.64.243', '99.229.98.18', '1', ['0, 1, 1, 0'],['0, 1, 1, 1'], 0.82 )
      ('188.74.64.243', '86.41.253.102', '1', ['0, 1, 1, 0'],['1, 1, 1, 1'], 0.70 )
      ('86.41.253.102', '99.229.98.18', '1', ['0, 1, 1, 1'],['1, 1, 1, 1'], 0.87 )
  </code></pre>