Last active
June 27, 2024 07:36
-
-
Save ArthurDelannoyazerty/01525649bb7011825bdf34ca585214a7 to your computer and use it in GitHub Desktop.
Code that gives a sorted file list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files = [f for f in os.listdir(gpx_folderpath) if os.path.isfile(os.path.join(gpx_folderpath, f))] | |
def sort_key(file): | |
num = re.search(r'(\d+)', file).group(1) | |
num = num.replace('-', ' ') | |
num = int(num) if num.isdigit() else 0 | |
return (num, file) | |
files.sort(key=sort_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With tthe line
files.sort(key=sort_key)
Without tthe line
files.sort(key=sort_key)