Index of maximum element in list
Sat Jan 26 08:40:28 CET 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))
I may have still missed something.
More information about the Python-list