title: Efficiently finding the closest coordinate pair from a set in Python
body: <p><strong>The Problem</strong></p>
  
  <p>Imagine I am stood in an airport. Given a geographic coordinate pair, how can one efficiently determine which airport I am stood in?</p>
  
  <p><strong>Inputs</strong></p>
  
  <ul>
  <li>A coordinate pair <code>(x,y)</code> representing the location I am stood at.</li>
  <li>A set of coordinate pairs <code>[(a1,b1), (a2,b2)...]</code> where each coordinate pair represents one airport.</li>
  </ul>
  
  <p><strong>Desired Output</strong></p>
  
  <p>A coordinate pair <code>(a,b)</code> from the set of airport coordinate pairs representing the closest airport to the point <code>(x,y)</code>.</p>
  
  <p><strong>Inefficient Solution</strong></p>
  
  <p>Here is my inefficient attempt at solving this problem. It is clearly linear in the length of the set of airports.</p>
  
  <pre><code>shortest_distance = None
  shortest_distance_coordinates = None
  
  point = (50.776435, -0.146834)
  
  for airport in airports:
      distance = compute_distance(point, airport)
      if distance &lt; shortest_distance or shortest_distance is None:
          shortest_distance = distance
          shortest_distance_coordinates = airport
  </code></pre>
  
  <p><strong>The Question</strong></p>
  
  <p>How can this solution be improved? This might involve some way of pre-filtering the list of airports based on the coordinates of the location we are currently stood at, or sorting them in a certain order beforehand.</p>