python sort file names with numbers

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']

Here is what the above code is Doing:
1. We create a list of filenames.
2. We sort the list using the sort() method.
3. We pass a key function to sort(). This function is used to extract a comparison key from each list element.
4. The key function we pass is a lambda function. This function takes a filename as input and returns the numeric part of the filename.
5. The numeric part of the filename is extracted using the filter() and isdigit() functions.
6. The numeric part of the filename is converted to an integer using the int() function.
7. The sorted() function sorts the list in ascending order by default.