Is there a simple way to find the list index to the max value?

Tim Golden mail at timgolden.me.uk
Tue Feb 16 14:53:18 EST 2010


On 16/02/2010 19:44, Aahz wrote:
> In article<4B7A91B1.6030301 at lonetwin.net>, steve<steve at lonetwin.net>  wrote:
>> On 02/16/2010 05:49 PM, W. eWatson wrote:
>>>
>>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2.
>>
>> The most obvious would be a.index(max(a)). Is that what you wanted ?
>
> The disadvantage of that is that it's O(2N) instead of O(N).

<Tongue-in-cheek> Well you could do this:

a.sort ()
return -1

TJG



More information about the Python-list mailing list