title: How to calculate distance between n coordinates in python
body: <p>I am working on a <code>python</code> project where from a function I am getting coordinate values <code>x, y</code> in a <code>dict</code> like below:</p>
  
  <p><code>centroid_dict = {0: (333, 125), 1: (288, 52), 2: (351, 41)}</code></p>
  
  <p>where <code>0, 1, 2</code> are the <code>objectId</code> and <code>(333, 125), (288, 52), (351, 41)</code> are their <code>(x, y)</code> coordinate values respectively.  I need to calculate the distance between each coordinate which means:</p>
  
  <pre><code>0 - 1 -&gt; ((333, 125) - (288, 52))
  
  0 - 2 -&gt; ((333, 125) - (351, 41))
  
  1 - 0 -&gt; ((288, 52) - (333, 125))
  
  1 - 2 -&gt; ((288, 52) - (351, 41))
  
  2 - 0 -&gt; ((351, 41) - (333, 125))
  
  2 - 1 -&gt; ((351, 41) - (288, 52))
  </code></pre>
  
  <p>To calculate the distance, I can use:</p>
  
  <pre><code>def calculateDistance(x1, y1, x2, y2):
      dist = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
      return dist
  </code></pre>
  
  <p>but I am not able to think of any logic which can calculate distance between each points as the length of dict might increase in future. As of now, it is <code>3</code> but it can be <code>10</code>. Can anyone please help me give some ideas on it. Thanks</p>