title: How to calculate distance between coordinates stored in a list?
body: <p>so I have two lists which each contain multiple points, like so :</p>
  <pre><code>list1 = [(1,2),(3,4),(5,6),(7,8),...]
  list2 = [(1,1),(2,2),(3,3,),...]
  </code></pre>
  <p>(these are just examples, as my normal data contains up to 10.000 points)</p>
  <p>I managed to calculate the distance between each point of one list to each point in the second list, with these lines of code :</p>
  <pre><code>dist = []
  from math import sqrt
  
  def distance(p1, p2):
      return sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)
  
  for p1 in list1:
      for p2 in list2:
          d = distance(p1, p2)
          dist.append(d)
  </code></pre>
  <p>(Note:  <code>dist = []</code> and <code>dist.append</code> are used for storing the calculated distances in a list)</p>
  <p>But infact for my analysis I only need the distances from the point in list1 to the nearest point in list2!</p>
  <p>To make this more understandable i plotted the points from my list here:
  <a href="https://i.stack.imgur.com/HDy0W.png" rel="nofollow noreferrer">Plotted points from list</a></p>
  <p>As you can see, for each blue point I only want to calculate the distance to the nearest red point, and not all of them.
  (I thought this could be done by calculating the distance from one blue point to all of the red ones, and then just storing the smallest distance, an/or discarding the other ones)</p>
  <p>Does anyone have an idea how this could be done ?</p>