I can do max(s) to find the max of a sequence. But suppose I want to compute max according to my own function , something like so -
currmax = 0
def mymax(s)
max(s, key=operator.methodcaller('arity'))
or
max(s, key=lambda x: x.arity())
You can still use the max
function:
max_arity = max(s, key=lambda i: i.arity())
I think the generator expression of doublep is better, but we seldom get to use methodcaller, so...
from operator import methodcaller
max(map(methodcaller('arity'), s))
For instance,
max (i.arity() for i in s)