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)
上一篇:Java工具类—包装类


下一篇:LeetCode 11.盛最多水的容器【Java】