I have the following string list. Then, I want to sort it by a number in each element. sorted
failed because it cannot handle the order such as between 10
and 3
. I can imagine if I use re
, I can do it. But it is not interesting. Do you guys have nice implementation ideas? I suppose python 3.x for this code.
names = [
'Test-1.model',
'Test-4.model',
'Test-6.model',
'Test-8.model',
'Test-10.model',
'Test-20.model'
]
number_sorted = get_number_sorted(names)
print(number_sorted)
'Test-20.model'
'Test-10.model'
'Test-8.model'
'Test-6.model'
'Test-4.model'
'Test-1.model'