How to sort the results of the glob function in python

Sorting the results of glob.glob() means ordering the list of file names based of specific criteria, such as alphabetically or by file size.

Solution for How to sort the results of the glob function in python : You can use sorted() to sort the file list Call sorted(glob_results) to automatically sort glob_results alphabetically by file name. By adding the second argument sorted(glob_results, key=criteria), the files will be sorted by what criteria dictates. For example, putting criteria as os.path.getsize will sort the files by size.


how-to-sort-the-results-of-the-glob-function-in-python