Max function question: How do I return the index of the maximum value of a list?
robert.kern at gmail.com
Mon Jun 5 03:52:12 CEST 2006
Steven Bethard wrote:
> Can you do something like::
> max_val, max_index = max((x, i) for i, x in enumerate(my_list))
> ? If any two "x" values are equal, this will return the one with the
> lower index. Don't know if that matters to you.
Wouldn't it return the one with the highest index?
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list