Cody Bable

Generation

generate functionTue, 23 May 2023

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

def find_nearest(list, value): return min(list, key=lambda x:abs(x-value)) list = [1, 4, 6, 9, 13, 18] find_nearest(list, 3)

Questions about programming?Chat with your personal AI assistant