0

how i can sort a list of list containing string and int..

user_list = [
    ['Jo Marat', 3],
    ['titi toto', 3],
    ['Mr DoD', 6],
    ['Zebrra Benda', 1]
]

sorted :

sorted_list = [
    ['Mr DoD', 6],
    ['Jo Marat', 3],
    ['titi toto', 3],
    ['Zebrra Benda', 1]
]

i try insertion algorithm but I dont' know how i can adapt this algo to my need...

Can you help me please ?

Pascal
  • 70
  • 7
  • Have you tried calling `.sort()` on the list, or passing it to `sorted()`? You can provide a `key` function that allows you to select a specific part of the elements. – Grismar Oct 17 '22 at 06:26
  • `sorted(user_list, key=lambda x: (-x[1], x[0]))` – mozway Oct 17 '22 at 06:27

0 Answers0