Max function question: How do I return the index of the maximum value of a list?
Steven Bethard
steven.bethard at gmail.com
Mon Jun 5 01:24:49 EDT 2006
Robert Kern wrote:
> 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?
Yes sorry. Mentally switched my min and max calls.
Thanks for the catch.
Steve
More information about the Python-list
mailing list