擅长:python、mysql、java
<p>这将返回所需的已排序列表:</p>
<pre><code>flist = [1.9842, 9.8713, 5.4325, 7.6855, 2.3493, 3.3333]
def listclamp(minn, maxn, nlist):
return sorted(filter(lambda x: xminn <= x <= maxn, nlist))
print listclamp(3, 8, flist)
</code></pre>
<p>一种使用<a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer">list comprehensions</a>更快的方法:</p>
^{pr2}$
<p>请注意,根据您的数据,最好先过滤列表,然后对其进行排序(正如我在上面的代码中所做的那样)。在</p>
<p>有关性能的详细信息,请参阅<a href="https://stackoverflow.com/a/3013686/963881">this link</a>。在</p>