Python: How to sort a list by the max of each element?

后端 未结 1 1731
遇见更好的自我
遇见更好的自我 2021-01-21 02:10
L=[[a,b],[c,d],[e,f],...]

I want to sort it by max(a,b), max(c,d), max(e,f), etc.

相关标签:
1条回答
  • 2021-01-21 02:57

    You can supply a custom key functor to sort:

    L.sort(key=max)
    
    0 讨论(0)
提交回复
热议问题