擅长:python、mysql、java
<p>您可以使用对分模块在有序列表中高效搜索位置:</p>
<pre><code>from bisect import bisect_left
def find_acres(a, L):
return bisect_left(L,a)+1
acres = 17.46 # Some value to test. The function should return `2`
acres_list = [15, 20, 25, 35, 45]
find_acres(10,acres_list) # 1
find_acres(17.46,acres_list) # 2
find_acres(35,acres_list) # 4
find_acres(100,acres_list) # 6
</code></pre>