dirFiles = ['Picture 03.jpg', '02.jpg', '1.jpg'] dirFiles.sort(key=lambda f: int(''.join(filter(str.isdigit, f)))) print(dirFiles) # ['1.jpg', '02.jpg', 'Picture 03.jpg']