排序需求:
排序代码实现:
import os
datadir = "D:\\xiangjun_data_2022_1_25\\signal\\signal\\DataSource_copy\\"
fig_save_dir = "D:/work/signal/signal/ims/"
list = os.listdir(datadir)
print(list)
print('------------after rank------------')
list_ranked = sorted(list, key=lambda x:(int((x.split(".")[0]).split('_')[0]), int((x.split(".")[0]).split('_') [1]),int((x.split(".")[0]).split('_')[2]), int((x.split(".")[0]).split('_')[3])))
print('len(list_ranked):',len(list_ranked))
print(list_ranked)
for item in list_ranked:
print(item)
排序结果
|