Cody Bable

Generation

generate functionTue, 23 May 2023

create a function of a set of integers and a value for which you need to find the nearest one.

def nearest_value(values: set, one: int) -> int: return min(values, key=lambda x: abs(x-one)) nearest_value({4, 7, 10, 11, 12, 17}, 9)

Questions about programming?Chat with your personal AI assistant