0
lst = [[1, 2, 3, 4], [10], [5, 6, 7, 8, [10, 20, 30, 40]]]
lst.sort(reverse=True)
print(lst)

The output of the above code is,

[[10], [5, 6, 7, 8, [10, 20, 30, 40]], [1, 2, 3, 4]]

I wrote this code to see how this list with sub lists is sorted, but seeing the result, I have no clue of how it is being sorted. Can anyone help me in this regard.

Thanks in advance!

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
Ankur Paul
  • 17
  • 1
  • 1
    When you compare two lists for sorting, it's based on the first element (unless you specify some other `key` function). So 10, 5, 1. – Samwise Sep 17 '20 at 16:06
  • @Samwise It also looks at subsequent items if the two it's comparing are equal – Random Davis Sep 17 '20 at 16:07

0 Answers0