finding max in python as per some custom criterion

Posted by MK on Stack Overflow See other posts from Stack Overflow or by MK
Published on 2010-05-28T19:42:22Z Indexed on 2010/05/28 19:51 UTC
Read the original article Hit count: 289

Filed under:
|

Hi,

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) :
  for i in s :
    #assume arity() attribute is present
    currmax = i.arity() if i.arity() > currmax else currmax

Is there a clean pythonic way of doing this?

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about pythonic