myArr = array([4,1,88,44,3])
myNumber = 25
FindClosest(myArr, myNumber)
...
4, 44
Is there any way to find the closest 2 numbers in a list to a given number such that one of them is higher and the other lower?
I can find the closest number by:
min(myArr.tolist(), key=lambda x:abs(x-myNumber))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…