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: values = sorted(values) min_idx = 0 max_idx = len(values) - 1 min_diff = abs(values[0] - one) min_value = values[0] while min_idx < max_idx: diff = abs(values[min_idx] - one) if diff < min_diff: min_diff = diff min_value = values[min_idx] min_idx += 1 return min_value

Questions about programming?Chat with your personal AI assistant