擅长:python、mysql、java
<p>您可以使用一个自然的排序键,非常容易用正则表达式<code>re.split()</code>进行设置</p>
<pre><code>import re
try:
# fast string checking and conversion
from fastnumbers import *
except:
pass
def natural_sort_key_for_list_of_lists(sublist):
return [int(element) if element.isdigit() else element
for element in re.split("([0-9]+)",sublist[0])]
# put whichever index of the sublist you want here ^
a = [["1", "ok", "na"],
["15", "asd", "asdasd"],
["100", "uhu", "plo"],
["10", "iju", "tlo"],
["ISC_1", "des", "det"],
["12", "asd", "assrg"],
["ARF", "asd", "rf"]]
a.sort(key=natural_sort_key_for_list_of_lists)
for l in a:
print (l)
</code></pre>
<p>结果:</p>
^{pr2}$