def main(a, b):
    for a_bound, a_val in a:
        dist_to_valid_b_points = {abs(a_val - b_val): (b_bound, b_val) for 
            b_bound, b_val in b if are_within_bounds(a_bound, b_bound)}
print(get_closest_point((a_bound, a_val), dist_to_valid_b_points))

def are_within_bounds(a_bound, b_bound):
    return abs(b_bound - a_bound) < 0.5

def get_closest_point(a_point, point_dict):
    return a_point, None if not point_dict else point_dict[min(point_dict,
        key=point_dict.get)]
Nearest neighbor 1 dimensional data with a specified range