Terry Reedy
1/26/2008 7:33:00 AM
"Henry Baxter" <henry.baxter@gmail.com> wrote in message
news:8d04436f0801251519g482a697dn625223b6d46e8f2c@mail.gmail.com...
| Thanks Hexamorph and Neal. Somehow I didn't make the connection with
using
| 'index', but I'm all sorted out now :)
|
| On Jan 25, 2008 1:47 PM, Hexamorph <hexamorph@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)) ?
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.