0

I got a list of lists like the one below

l = [
    [1, ....],
    [2, ....],
    [3, ....],
]

And I want as a result the list with the bigger number as the first element.

So the result of the above list should be:

[3, ....],

If we get multiple times the highest number, just get one of them in random

Any ideas on how to achieve that?

Thanks a ton!

  • 1
    Does this answer your question? [Sorting list of lists by the first element of each sub-list](https://stackoverflow.com/questions/36955553/sorting-list-of-lists-by-the-first-element-of-each-sub-list) – Mady Daby May 26 '21 at 17:55
  • you can pass a key arg on sorted inbuilt method; ```sorted(my_cool_list, key=lambda my_list: my_list[0])``` – Aditya May 26 '21 at 17:56

1 Answers1

1

Try this.

new_l = sorted(l,key=lambda x : x[0],reverse=True)

If you want only first sorted list

new_l[0]
user1101221
  • 394
  • 6
  • 21