擅长:python、mysql、java
<p>如果只需要得到一个值,则不需要对列表进行排序。使用内置的<a href="https://docs.python.org/3/library/functions.html?highlight=max#max" rel="nofollow">^{<cd1>}</a>函数和这样的自定义排序函数</p>
<pre><code>In [3]: max(l, key=lambda x: x[0])[1] # compare first elements of inner lists
Out[3]: 'Percent Cats'
</code></pre>
<p>甚至</p>
<pre><code>In [4]: max(l)[1] # compare lists directly
Out[4]: 'Percent Cats'
</code></pre>
<p>后面的代码也可以工作,因为<a href="https://docs.python.org/3/tutorial/datastructures.html#comparing-sequences-and-other-types" rel="nofollow"><em>sequence objects may be compared to other objects with the same sequence type</em></a>:</p>
<blockquote>
<p>The comparison uses lexicographical ordering: first the first two
items are compared, and if they differ this determines the outcome of
the comparison; if they are equal, the next two items are compared,
and so on, until either sequence is exhausted. If all items of
two sequences compare equal, the sequences are considered equal.</p>
</blockquote>