Cody Bable

Generation

generate functionTue, 23 May 2023

def nearest_value(values: set[int], one: int) -> int:

def nearest_value(values: set[int], one: int) -> int: l = sorted(list(values)) i = bisect_left(l, one) if i == len(l): return l[i-1] if i == 0: return l[i] return l[i-1] if abs(l[i-1] - one) < abs(l[i] - one) else l[i]

Questions about programming?Chat with your personal AI assistant