1

I have the following list:

['God: 250', 'Noob: 0', 'Bot: 20']

I would like to sort the list in ascending order using the numbers at the end of each element. The end product should look something like this:

['Noob: 0', 'Bot: 20', 'God: 250']

I have had a look at other solutions in this question but have had no luck. Any help is appreciated.

SOLUTION

list.sort(key=lambda x: int(x.split(":")[1].strip()))

ahmedquran12
  • 164
  • 1
  • 6
  • 19

1 Answers1

0
print(sorted(myList, key=lambda x: int("".join([i for i in x if i.isdigit()]))))