code: def get_flanker(group, query):
      
      group.sort()
      pos = bisect_left(group, (query, 0))
      left_flanker = group[0] if pos == 0 else group[pos-1]
      right_flanker = group[-1] if pos == len(group) else group[pos]
      # pick the closest flanker
      if abs(query - left_flanker[0]) < abs(query - right_flanker[0]):
          flanker, other = left_flanker, right_flanker
      else:
          flanker, other = right_flanker, left_flanker
  
      flanked = not (pos == 0 or pos == len(group) or flanker == query)
  
      return flanker, other, flanked
docs: >>> get_flanker([(370, 15184), (372, 15178), (373, 15176), (400, 15193)],  385)
      ((373, 15176), (400, 15193), True)
  
      >>> get_flanker([(124, 13639), (137, 13625)], 138)
      ((137, 13625), (137, 13625), False)