# find最接近列表中未完全sorting值的项目的索引

``[25.75443, 26.7803, 25.79099, 24.17642, 24.3526, 22.79056, 20.84866, 19.49222, 18.38086, 18.0358, 16.57819, 15.71255, 14.79059, 13.64154, 13.09409, 12.18347, 11.33447, 10.32184, 9.544922, 8.813385, 8.181152, 6.983734, 6.048035, 5.505096, 4.65799]` `

### 6 Solutions collect form web for “find最接近列表中未完全sorting值的项目的索引”

` `min(range(len(a)), key=lambda i: abs(a[i]-11.5))` `

` `>>> a = [25.75443, 26.7803, 25.79099, 24.17642, 24.3526, 22.79056, 20.84866, 19.49222, 18.38086, 18.0358, 16.57819, 15.71255, 14.79059, 13.64154, 13.09409, 12.18347, 11.33447, 10.32184, 9.544922, 8.813385, 8.181152, 6.983734, 6.048035, 5.505096, 4.65799] >>> min(range(len(a)), key=lambda i: abs(a[i]-11.5)) 16` `

` `>>> min(enumerate(a), key=lambda x: abs(x[1]-11.5)) (16, 11.33447)` `

[编辑]使用`zip()` ，这是非常简单的实现：

` ` array_to_sort = zip( original_array, range(len(original_array)) ) array_to_sort.sort( key=i:i[0] )` `

` `import numpy as np a = [25.75443, 26.7803, 25.79099, 24.17642, 24.3526, 22.79056, 20.84866, 19.49222, 18.38086, 18.0358, 16.57819, 15.71255, 14.79059, 13.64154, 13.09409, 12.18347, 11.33447, 10.32184, 9.544922, 8.813385, 8.181152, 6.983734, 6.048035, 5.505096, 4.65799] index = np.argmin(np.abs(np.array(a)-11.5)) a[index] # here is your result` `

• 全文searchInnoDB
• 无法像CTRL-r一样转发searchBash历史logging
• PHP在txt文件内search并回显整个行
• 文本search虽然Xcode中的所有.xib文件？
• 在MySQL的文本列中searchstring
• 如何在JavaScript中的多维对象/数组中find一个值？
• Java中的模糊stringsearch库
• 一个更好的相似性sortingalgorithm的变长string