A maxby(list, f) takes a list of objects and a function f as arguments, such that f applied to any object in the list returns a number. Then maxby returns the object x in the list for which f(x) is maximum.
What's the pythonic way to write something like maxby(list, f)? Is it already implemented, or I have to write one?
It's builtin in Python, just use max() function with key parameter:
max(list, key=f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With