本文主要是介绍2021-09-07: python对中文名称重排序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
对中文名称重排序
import functools
def cmp_str(s1, s2):
pos1 = s1.find('-')
pos2 = s2.find('-')
i1 = int(s1[:pos1])
i2 = int(s2[:pos2])
if i1 < i2:
return -1
if i1 > i2:
return 1
return 0
with open('E:\\vidlist.txt','r',encoding='UTF-8') as vislst:
vlst = vislst.readlines()
for v in vlst:
v=v.strip()
pos = v.find('-')
try:
i = int(v[:pos])
except:
print(v[:pos])
vlst = list(map(str.strip, vlst))
vlst.sort(key=functools.cmp_to_key(cmp_str))
for vid in vlst:
print(vid)
这篇关于2021-09-07: python对中文名称重排序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!