From 330a2bbf9704b672fcc237c3d44e68bb2bad4109 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 15 Jul 2024 16:04:49 +0100 Subject: sort by int value --- challenge-278/steven-wilson/python/ch-1.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/challenge-278/steven-wilson/python/ch-1.py b/challenge-278/steven-wilson/python/ch-1.py index 8e113ff425..18b5904a2a 100644 --- a/challenge-278/steven-wilson/python/ch-1.py +++ b/challenge-278/steven-wilson/python/ch-1.py @@ -16,8 +16,9 @@ def sort_string(string): 'The Weekly Challenge' """ p = re.compile('^(\w+)(\d+)$') - words_sorted = sorted((p.search(word).groups() for word in string.split(" ")), key=itemgetter(1)) - return " ".join(word[0] for word in words_sorted) + words_numbers = (p.search(word).groups() for word in string.split(" ")) + words_numbers_sorted = sorted(((w[0], int(w[1])) for w in words_numbers), key=itemgetter(1)) + return " ".join(word[0] for word in words_numbers_sorted) if __name__ == "__main__": -- cgit