Python3粗略实现【windows 文件名称排序】的风格,自
import re
import functools
def natural_key(astr):
return [int(s) if s.isdecimal() else s for s in re.split(r'(\d+)', astr)]
def natural_cmp(a, b):
key_a = natural_key(a)
key_b = natural_key(b)
if key_a > key_b:
return 1
if key_a < key_b:
return -1
if key_a == key_b:
return 0
def tcmp(a, b):
return natural_cmp(a["name"], b["name"])
results=[]
sorted(results, key=functools.cmp_to_key(tcmp))
本文标题:Python3粗略实现【windows 文件名称排序】的风格,自
本文链接:https://www.haomeiwen.com/subject/jjhpohtx.html
网友评论