擅长:python、mysql、java
<p><code>range</code>定义为<code>range(start, stop, step)</code>,不包括stop参数</p>
<p>定义为<code>sorted(iterable, key=key, reverse=reverse)</code>的<code>sorted</code>似乎是这样工作的:</p>
<p>输出原始输入值,但按键排序,在本例中按其平方排序。正方形将负值转换为正值,然后应用排序,最后按顺序返回原始值</p>
<p>在命令行上对此进行了测试:</p>
<pre><code>print(sorted(range(-3,4)))
# [-3, -2, -1, 0, 1, 2, 3]
print(sorted(range(-3,4), key=lambda x: x*x))
# [0, -1, 1, -2, 2, -3, 3]
</code></pre>
<p>(a1);;它表示<code>sorted()</code>(以及<code>sort()</code>)排序都是<strong>稳定的</strong>:</p>
<blockquote>
<p>Sorts are guaranteed to be stable. That means that when multiple records have the same key, their original order is preserved.</p>
</blockquote>