list_ybjz_name =['C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)1.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)10.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)11.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)12.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)13.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)14.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)15.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)16.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)17.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)18.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)2.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)3.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)4.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)5.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)6.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)7.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)8.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)9.xlsx']
# 对列表中的应变计组文件名进行按名称最后的数字进行排序
list_ybjz_name = sorted(list_ybjz_name,key=lambda s:int(s.split('(5)')[1].split('.')[0]))
排序后的结果:
['C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)1.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)2.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)3.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)4.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)5.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)6.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)7.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)8.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)9.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)10.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)11.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)12.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)13.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)14.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)15.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)16.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)17.xlsx', 'C:\\Users\\Thinkpad\\Desktop\\临时数据表格\\应变计组s(5)18.xlsx']