Cody Bable

Generation

generate functionTue, 23 May 2023

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

def nearest_value(values: set, one: int) -> int: lst = list(values) lst.sort() for i in range(len(lst)): if lst[i] >= one: if i == 0: return lst[i] else: if lst[i] - one >= one - lst[i-1]: return lst[i-1] else: return lst[i] return lst[-1]

Questions about programming?Chat with your personal AI assistant