python get nearest value in list

Solutions on MaxInterview for python get nearest value in list by the best coders in the world

showing results for - "python get nearest value in list"
Dario
02 Oct 2019
1def takeClosest(num,collection):
2   return min(collection,key=lambda x:abs(x-num))