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 find_nearest(val, set_of_vals): return min(set_of_vals, key=lambda x:abs(x-val)) find_nearest(5.1, [5, 6, 3, 8, 2])

Questions about programming?Chat with your personal AI assistant