针对不同命名规范下的version排序


import pprint
version = ['0.1.5', '2.10.1', '10.2.3','0.1.023','16.0.0','4.5.2','0.10.2']

def group_version(index, version_list):
    all_num = sorted(list(set([s.split('.')[index] for s in version_list])))
    all_num.sort(key=int)
    group = []
    for i in all_num:
        group.append([])
    version_list.sort(key=lambda x: int(x.split('.')[index]))

    for i in version_list:
        inx = all_num.index(i.split('.')[index])
        group[inx].append(i)
    return group

version1 = group_version(0, version)

sort_version = []
for ver1 in version1:
    version2 = group_version(1, ver1)
    for n, ver2 in enumerate(version2):
        sort_version.extend(sorted(ver2, key=lambda x: int(x.split('.')[1])))

print(sort_version)

评论
  目录