python 数组按文件名排序
展开阅读全文

python 数组按文件名排序

安装

pip install natsort
# 我用的是8.1.0版本的
pip install natsort==8.1.0

使用:

from natsort import natsorted
a = ['1.mp4', '3.mp4', '10.mp4', '2.mp4']
b = natsorted(a)
print(b)

常规排序sort()

a = ['1.mp4', '3.mp4', '10.mp4', '2.mp4']
a.sort()
print(a)

但是常规的针对文件名没啥效果