Finding maximum of a list of lists by sum of elements in Python
Posted
by Don Stewart
on Stack Overflow
See other posts from Stack Overflow
or by Don Stewart
Published on 2010-05-04T05:32:29Z
Indexed on
2010/05/04
5:38 UTC
Read the original article
Hit count: 274
What's the idiomatic way to do maximumBy (higher order function taking a comparison function for the test), on a list of lists, where the comparison we want to make is the sum of the list, in Python?
Here's a Haskell implementation and example output:
> maximumBy (compare `on` sum) [[1,2,3],[4,5,6],[1,3,5]]
> [4,5,6]
© Stack Overflow or respective owner