擅长:python、mysql、java
<p>由于排序是<a href="https://docs.python.org/3/howto/sorting.html#sort-stability-and-complex-sorts" rel="nofollow noreferrer">guaranteed to be stable</a>,您可以通过两个步骤来完成:</p>
<pre><code>lst = [(2, 'Operation.SUBSTITUTED'), (1, 'Operation.DELETED'), (2, 'Operation.INSERTED')]
res_int = sorted(lst, key=lambda x: x[1], reverse=True)
res = sorted(res_int, key=lambda x: x[0])
print(res)
# [(1, 'Operation.DELETED'), (2, 'Operation.SUBSTITUTED'), (2, 'Operation.INSERTED')]
</code></pre>