"Henry Baxter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | 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 <[EMAIL PROTECTED]> 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. -- http://mail.python.org/mailman/listinfo/python-list