From a3b1634f2de21dcb6cdea0a5101837b7898366e8 Mon Sep 17 00:00:00 2001 From: David Barroso Date: Sat, 23 May 2015 09:36:30 +0200 Subject: [PATCH] Interfaces are sorted in get_facts --- utils/string_parsers.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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: