min, max with position

dn PythonList at DancesWithMice.info
Sat Jun 4 18:07:42 EDT 2022


On 05/06/2022 09.50, Chris Angelico wrote:
> No, but it shouldn't be too hard to make it if you want it. The
> obvious option of calling max/min on the enumerated list won't work on
> its own, since the index comes before the value, but with a key
> function it would work fine:
> 
>>>> min(enumerate(l), key=lambda x: x[1])
> (0, 1.618033)
>>>> max(enumerate(l), key=lambda x: x[1])
> (1, 3.141593)

An elegant solution!

But, but, but which of the above characters is an 'el' and which a 'one'???
(please have pity on us old f...s and the visually-challenged!)

-- 
Regards,
=dn


More information about the Python-list mailing list