On 2010-02-16 11:44:45 -0800, a...@pythoncraft.com (Aahz) said:
In article <4b7a91b1.6030...@lonetwin.net>, steve <st...@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).
I don't think you understand order notation. There's no such thing as O(2N).
To answer the original question, how about:
max(enumerate(l), key=lambda x: x[1])[0]
As to whether this is faster than index(max()), you'd have to time it.
-Tom
--
http://mail.python.org/mailman/listinfo/python-list