from time import time
a = ['file1.txt',
'file10.txt',
'file2.txt'] * 1000
s = time()
sorted(a, key=lambda x: int(x[4:-4]))
print(st:=time()-s)
b = time()
number = slice(4, -4)
sorted(a, key=lambda name: int(name[number]))
print(bt:=time()-s)
print(bt-st)
говорить по факту