擅长:python、mysql、java
<p>您想测试序列(不包括未定义的值)是否按升序排列:</p>
<pre><code>import operator
def isAscending(strictly, *seq):
cmp_op = operator.lt if stricly else operator.le
seq = [e for e in seq if e is not None]
return all(cmp_op(a, b) for a, b in zip(seq, seq[1:]))
a, b, c = 1, None, 2
print isAscending(True, a, b, c) # strictly ascending ?
</code></pre>
<p>为拼写编辑,并按建议使用比较运算符。在</p>