maximum element?

Thorsten Kampe thorsten at thorstenkampe.de
Wed Apr 28 18:55:29 EDT 2004


Catching up...

* Ivan Voras (2004-03-04 22:52 +0100)
> What is the 'most pythonic' way of searching the largest element in a 
> list/tuple?
> 
> My 'standard' idea is:
> 
> max = list[0]   # or -infinity, or whatever...
> for i in list:
>      if i > max:
>          max = i
> 
> While this is ok, I somehow 'feel' there could be a more concise 
> solution... :)

max(seq)

In a real world example you wouldn't be interested in "the" maximum
but in the extrema/maxima according to function f (in your case the
identity f(x)=x), which could be more than just one item.

Thorsten



More information about the Python-list mailing list