擅长:python、mysql、java
<p>好的,那么您想要的是首先对startX进行排序,然后对startY进行排序,同时考虑startX中元素之间的相对顺序。
它看起来是这样的:</p>
<pre><code># Input:
[[ 27, 22, 84 , 54],
[261 ,127 ,294 ,163],
[224 , 21 ,279 , 54],
[ 45 ,83 , 96 ,111],
[ 10 ,126 , 66 ,163],
[189 ,185 ,219 ,222],
[154 , 21 ,192 , 59],
[278 , 25 ,318 , 58],
[146 ,188 ,186, 220]]
# First sort:
[[ 10 ,126 , 66 ,163],
[ 27, 22, 84 , 54],
[ 45 ,83 , 96 ,111],
[146 ,188 ,186, 220],
[154 , 21 ,192 , 59],
[189 ,185 ,219 ,222],
[224 , 21 ,279 , 54],
[261 ,127 ,294 ,163],
[278 , 25 ,318 , 58]]
# Second sort:
[[154 , 21 ,192 , 59],
[224 , 21 ,279 , 54],
[ 27, 22, 84 , 54],
[278 , 25 ,318 , 58],
[ 45 ,83 , 96 ,111],
[ 10 ,126 , 66 ,163],
[261 ,127 ,294 ,163],
[146 ,188 ,186, 220],
[189 ,185 ,219 ,222]]
</code></pre>
<p>这就是所谓的稳定排序。
现在,根据<a href="https://docs.python.org/3/library/functions.html#sorted" rel="nofollow noreferrer">standard library reference</a>,<code>sorted</code>函数实现了一个稳定的排序</p>