I have a list of strings in python that looks like this:
How can I sort it by the last number?
Like that:
sorted(your_list, lambda x: int(x.split()[-1]))
my_list = ['abc 12 34 3333',
'def 21 43 2222',
'fgh 21 43 1111']
my_list.sort(key=lambda x:int(x.split()[-1]))
my_list
is now: ['fgh 21 43 1111', 'def 21 43 2222', 'abc 12 34 3333']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With