Skip to content Skip to sidebar Skip to footer

Python: How To Sort A List By The Max Of Each Element?

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

Solution 1:

You can supply a custom key functor to sort:

L.sort(key=max)

Post a Comment for "Python: How To Sort A List By The Max Of Each Element?"