Skip to content

Instantly share code, notes, and snippets.

@hctilg
Created December 31, 2024 10:51
Show Gist options
  • Save hctilg/848bed4aaa60de24da68a8eeff3d4a97 to your computer and use it in GitHub Desktop.
Save hctilg/848bed4aaa60de24da68a8eeff3d4a97 to your computer and use it in GitHub Desktop.
import os
import re
images = [img for img in os.listdir(folder_path) if img.endswith(('.png', '.jpg', '.jpeg'))]
images.sort(key=lambda filename: [int(text) if text.isdigit() else text for text in re.split('([0-9]+)', filename)])
print(images)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment