擅长:python、mysql、java
<p>您可以使用<a href="http://docs.python.org/3/library/stdtypes.html#list.sort" rel="nofollow">^{<cd1>}</a>,它的<a href="http://docs.python.org/3/glossary.html#key-function" rel="nofollow">key function</a>,和<a href="http://docs.python.org/3/library/operator.html#operator.itemgetter" rel="nofollow">^{<cd2>}</a>:</p>
<pre><code>>>> from operator import itemgetter
>>> example = [['b',1],['b',2],['a',2]]
>>> example.sort(key=itemgetter(1,0))
>>> example
[['b', 1], ['a', 2], ['b', 2]]
>>>
</code></pre>
<hr/>
<p>您还可以使用<a href="http://docs.python.org/3/tutorial/controlflow.html#lambda-expressions" rel="nofollow">^{<cd3>}</a>代替<code>operator.itemgetter</code>:</p>
^{pr2}$
<p>但那会比较慢。在</p>