擅长:python、mysql、java
<p>那怎么办?你知道吗</p>
<pre><code>lst = [('Paul George', 1), ('Luke Skywalker', 2), ('Mitchell Piker', 3), ('Phil Dam', 1)]
[(n,-i) for (i,n) in sorted([(-i,n) for (n,i) in lst])]
[('Mitchell Piker', 3),
('Luke Skywalker', 2),
('Paul George', 1),
('Phil Dam', 1)]
</code></pre>
<p>解释:<code>sorted</code>做你想做的,除了:</p>
<ul>
<li><p>它将首先根据第一个元素(名称)排序</p></li>
<li><p>然后根据第二个元素(数字)排序,但也按升序排序</p></li>
</ul>
<p>所以要解决这个问题:将它与元素交换以及否定数字结合起来。你知道吗</p>