Index of maximum element in list
Paul Rubin
http
Sat Jan 26 02:40:28 EST 2008
"Terry Reedy" <tjreedy at udel.edu> writes:
> | > What's about l.index(max(l)) ?
>
> Both of these methods scan the list twice. The two given by RH and SDD do
> so just once. Both of those will give the index of the of the last maximum
> value. If you want the index of the first max value (you did not specify
> ;-), write an explicit loop.
How about (corrected but still untested):
-max((v,-i) for i,v in enumerate(l))[1]
I may have still missed something.
More information about the Python-list
mailing list