Jul-18-2021, 08:14 AM
Bruteforce-Method:
(1, 1, 4) < (23,)
(23,) < (33, 42)
(33, 43) < (55,)
import re def number_tuple(text: str) -> tuple[int]: """ Return number pairs """ return tuple(int(val) for val in re.split(r"\D+", text) if val) items = ["AA33_43", "A", "A23", "B55", "1_1_4"] sorted(items, key=number_tuple)
Output:['A', '1_1_4', 'A23', 'AA33_43', 'B55']
A
returns an empty tuple, so it's the first item.(1, 1, 4) < (23,)
(23,) < (33, 42)
(33, 43) < (55,)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!