On 04/06/2022 14.08, Stefan Ram wrote:
"Michael F. Stemper" <michael.stem...@gmail.com> writes:
Are there similar functions that return not only the minimum
or maximum value, but also its position?

   The maximum value does not need to have a unique position.

Which is something that I'll just have to live with, whether I
use home-brew or something from a standard module. For the particular
application, my lists have 24 elements and are converted from data
that is received in a %5.2f format, so collisions aren't too likely
anyway.

   The World-Wide Web holds several suggestions like l.index(
   max( l )) or max( enumerate( l ), key=( lambda x: x[ 1 ])).

Oh, I like that second one. I tried playing around with a lambda
function, but combining with enumerate eluded me. It's much better
than my for-loop with extraneous variables.

--
Michael F. Stemper
Psalm 94:3-6
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to