pcmdi_metrics.utils.sort_human
- pcmdi_metrics.utils.sort_human(input_list)[source]
Sort a list of strings in natural order.
This function sorts a list of strings using a natural sorting algorithm, which means that strings containing numbers are sorted in a way that respects numerical order within the string.
- Parameters:
input_list (
list
ofstr
) – The input list of strings to be sorted.- Returns:
list
ofstr
– A new list containing the input strings sorted in natural order.
Notes
The natural sorting algorithm used in this function considers the numerical values within strings when determining the sort order. For example, “file2” will be sorted before “file10”.
Examples
>>> from pcmdi_metrics.utils import sort_human >>> sort_human(['file1', 'file10', 'file2']) ['file1', 'file2', 'file10']
>>> sort_human(['1.txt', '10.txt', '2.txt', 'foo.txt']) ['1.txt', '2.txt', '10.txt', 'foo.txt']