Index of maximum element in list

Henry Baxter henry.baxter at gmail.com
Fri Jan 25 22:39:35 CET 2008


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

But it seems like something that should be built in - or at least I should
be able to write a lambda function for it, but I'm not sure how to do that
either...Suggestions are very much welcome!

On Jan 25, 2008 1:37 PM, Henry Baxter <henry.baxter at gmail.com> wrote:

> I apologize if this has already been discussed - funnily enough my
> googling did bring up a previous thread about it on this mailing list, but
> despite the promising subject line, seemed to mainly be concerned with
> whether python-list should its own FAQ...so I assume this has been asked
> many times before, but my apologies I cannot find the answer. Here is what I
> have:
>
> def maxi(l):
>
> it
> --
> Henry




-- 
Henry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080125/6fe8d12d/attachment.html>


More information about the Python-list mailing list