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_closest(lst, K): return lst[min(range(len(lst)), key = lambda i: abs(lst[i]-K))] # Driver code lst = [4, 7, 10, 11, 12, 17] K = 13 print(find_closest(lst, K))

Questions about programming?Chat with your personal AI assistant