aboutsummaryrefslogtreecommitdiff
path: root/challenge-278
diff options
context:
space:
mode:
authorSteven <steven1170@zoho.eu>2024-07-15 16:04:49 +0100
committerSteven <steven1170@zoho.eu>2024-07-15 16:04:49 +0100
commit330a2bbf9704b672fcc237c3d44e68bb2bad4109 (patch)
treef80cc8cf302b98771f01b6152062a7b11851fe6e /challenge-278
parent3a5c11a1c8a2d1e0f94c9ae9c732740f88b4bcd2 (diff)
downloadperlweeklychallenge-club-330a2bbf9704b672fcc237c3d44e68bb2bad4109.tar.gz
perlweeklychallenge-club-330a2bbf9704b672fcc237c3d44e68bb2bad4109.tar.bz2
perlweeklychallenge-club-330a2bbf9704b672fcc237c3d44e68bb2bad4109.zip
sort by int value
Diffstat (limited to 'challenge-278')
-rw-r--r--challenge-278/steven-wilson/python/ch-1.py5
1 files 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__":