擅长:python、mysql、java
<p>这看起来像是您实际上在尝试测试您的值是否是唯一的,并且是按排序顺序排列的,这些值可以替换为以下内容:</p>
<pre><code>>>> def my_test(l):
>>> filt_l = [v for v in l if not v is None]
>>> return (sorted(filt_l) == filt_l) and (len(filt_l) == len(set(filt_l)))
>>> my_test([1,2,3])
True
>>> my_test([1,None,3])
True
>>> my_test([1,4,3])
False
>>> my_test([1,1,3])
False
</code></pre>
<hr/>
<p><strong>编辑:</strong>包括计时,sebdelsol建议的功能似乎更快</p>
^{pr2}$