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.

l = [1, 2, 4, 5, 6, 7, 9] def find_nearest(l, x): return min(l, key=lambda y:abs(y-x)) find_nearest(l, 3)

Questions about programming?Chat with your personal AI assistant