title: Find the closest and the farthest points (2D) between a given point and a list of points in python
body: <p>So I am trying to write a python function that can take any given point say <strong>(1,2)</strong> we can call this a <strong>point of interest</strong> and then take a <strong>list of points</strong> say <strong>[(6,2), (4,5), (3,4),...]</strong> the function should return the points (from the list) that are <strong>closest</strong> and <strong>farthest</strong> to our point of interest.</p>
  <p>The function should accept two parameters:</p>
  <pre><code>    1. Point of interest i.e. pos=(1,2)
      2. List of points i.e. ptlist=[(1,3),(6,2), (4,5), (3,4)]
  </code></pre>
  <p>Also the function should return answers in a form of ((1,3),(4,5)) i.e (closest,farthest)</p>
  <p>Here is my code, so far this works but it returns the numpy arrays, while I want my answers to be tuples. I have tried different ways and whatever I try I can't seem to get it right. Maybe we could use something else apart from numpy just so that we get answers in a form of ((1,3),(4,5)).</p>
  <p>Here is the code I've written so far:</p>
  <pre class="lang-py prettyprint-override"><code>pos=(1,2)
  ptlist=[(2, 6), (8,6), (5,8), (2,4)]
  def get_nearest_farthest(pt, ptlist):
      pt=np.array(pt)
      ptlist=np.array(ptlist)
      dist=np.linalg.norm(ptlist-pt, axis=1)
      min_index = np.argmin(dist)
      #tuple(map(tuple,ptlist[min_index])) #Error
      max_index = np.argmax(dist)
      #tuple(map(tuple,ptlist[max_index])) #Error
      return ptlist[min_index],ptlist[max_index]
  
  get_nearest_farthest(pt, ptlist)
  </code></pre>