diff --git a/utils/string_parsers.py b/utils/string_parsers.py index 08ac9a9..1d71cd4 100644 --- a/utils/string_parsers.py +++ b/utils/string_parsers.py @@ -1,3 +1,11 @@ +import re + +def sorted_nicely( l ): + """ Sort the given iterable in the way that humans expect.""" + convert = lambda text: int(text) if text.isdigit() else text + alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] + return sorted(l, key = alphanum_key) + def colon_separated_string_to_dict(string, separator=':'): ''' Converts a string in the format: