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 closest_int_to(a, b): return sorted(a, key = lambda x: abs(x-b))[0] closest_int_to([10, 11, 12, 13, 14], 9)

Questions about programming?Chat with your personal AI assistant