Index of maximum element in list

Raymond Hettinger python at rcn.com
Fri Jan 25 23:16:50 EST 2008


On Jan 25, 1:47 pm, Hexamorph <hexamo... at gmx.net> wrote:
> Henry Baxter wrote:
> > Oops, gmail has keyboard shortcuts apparently, to continue:
>
> > def maxi(l):
> >     m = max(l)
> >     for i, v in enumerate(l):
> >         if m == v:
> >             return i
>
> What's about l.index(max(l)) ?

from itertools import izip, count
answer  = max(izip(l, count()))[1]


Raymond



More information about the Python-list mailing list