Search
 
SCRIPT & CODE EXAMPLE
 

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))
Comment

PREVIOUS NEXT
Code Example
Python :: selenium python class contains 
Python :: pandas check if value in column is in a list 
Python :: what is join use for in python 
Python :: python remove background 
Python :: python get address of object 
Python :: tkinter open new window 
Python :: selenium get parent element python 
Python :: check if string has digits python 
Python :: How do I get the parent directory in Python? 
Python :: python web parser 
Python :: python generate id 
Python :: how do you see if a data type is an integer python 
Python :: python get dictionary keys 
Python :: how to pair up two lists in python 
Python :: how to add delay in python 
Python :: decorator python 
Python :: python get response from url 
Python :: django on_delete options 
Python :: virtual enviroment 
Python :: python remove none from dict 
Python :: pandas dataframe total row 
Python :: Simple way to measure cell execution time in jupyter notebook 
Python :: current date to epoch python 
Python :: dataframe groupby multiple columns 
Python :: create a list of a certain length python 
Python :: death stranding 
Python :: python with file 
Python :: python api define bearer token 
Python :: python datetime day of year 
Python :: swapping of two numbers in python 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =