a = [13.6, 13.0, 12.1, 11.3, 10.3, 9.0, 8.8, 8.1] #list
value = 11.5 #value to find
min(range(len(a)), key=lambda i: abs(a[i]- value)) #just index
#result: 3
min(enumerate(a), key=lambda x: abs(x[1]-value)) #index and value
#result: (3, 11.3)
def closest(lst, K):
return lst[min(range(len(lst)), key = lambda i: abs(lst[i]-K))]
# Driver code
lst = [3.64, 5.2, 9.42, 9.35, 8.5, 8]
K = 9.1
print(closest(lst, K))
min(range(len(a)), key=lambda i: abs(a[i]-11.5))
min(range(len(a)), key=lambda i: abs(a[i]-11.5))