Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python find closest value in list

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))
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #python #find #closest #list
ADD COMMENT
Topic
Name
1+9 =