title: Comparing X Y coordinates of the same list
body: <p>I have a list of X Y tuple coordinates. I am trying to eliminate the coordinates that are very close to each other using the euclidean distance. However, the code so far does not perform as expected, especially as the number of coordinates increases. </p>
  
  <p>So far, I have found online how to compare two lists of coordinates, but not the elements within the same list. 
  Hence, what i have done is slice the list in the first element and the remainder of the list and so the euclidean distance comparison. If within the proximity, it is element value is removed from the list. Then the list is updated and the procedure repeated. However, it does not perform as expected. </p>
  
  <pre><code>from scipy.spatial import distance
  
  # List of coordinates.
  xy = [(123, 2191), (44, 2700), (125, 2958), (41, 3368), (33, 4379), (78, 4434), (75, 5897), (50, 6220), (75, 7271), (80, 7274), (58, 8440), (60, 8440), (59, 8441), (32, 9699), (54, 9758), (58, 9759), (43, 10113), (64, 10252), (57, 12118), (61, 12120), (60, 14129), (61, 14129), (66, 15932), (68, 15933), (53, 17302), (57, 17304), (84, 20012), (84, 20013), (102, 20222), (49, 21257), (47, 21653), (56, 27042), (51, 28200), (48, 28201), (55, 28202), (65, 29366), (43, 29484), (67, 29808), (32, 30840), (31, 30842), (48, 36368), (48, 36369), (49, 36369), (21, 37518), (102, 37519)]
  
  uni = []
  for x in xy[:]:
      for i, j in enumerate(xy):
          if i == 0:
              new_xy = j # New List comprising of first element of the list
      remaining_xy = list(set(xy) - set(new_xy)) # rest of list converted into a separate list
      for m in remaining_xy:
          print(new_xy , m, distance.euclidean(new_xy , m))
          if distance.euclidean(new_xy ,m) &lt; 1000: # If distance less then threshold, remove. 
              remaining_xy.remove(m)
  
      xy = remaining_xy #reset xy
      remaining_xy = [] #reset remaining_xy
      uni.append(new_xy) # append unique values. 
  
  print(len((uni)), uni)
  </code></pre>
  
  <p>However, for example, the output shows </p>
  
  <blockquote>
    <p>..., (53, 17302), (57, 17304), ...</p>
  </blockquote>
  
  <p>Which does not satisfy the threshold. </p>