maximum element?

Robert Kern rkern at ucsd.edu
Thu Mar 4 16:13:34 EST 2004


Ivan Voras wrote:
> What is the 'most pythonic' way of searching the largest element in a 
> list/tuple?

max(list)

> 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... :)

Indeed.  :-)

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the Python-list mailing list