min, max with position
Antoon Pardon
antoon.pardon at vub.be
Sun Jun 5 04:46:40 EDT 2022
Op 5/06/2022 om 01:52 schreef Greg Ewing:
> On 5/06/22 10:07 am, dn wrote:
>> On 05/06/2022 09.50, Chris Angelico wrote:
>>>>>> min(enumerate(l), key=lambda x: x[1])
>>> (0, 1.618033)
>>
>> 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!)
>>
>
> ell = l
> one = 1
> min(enumerate(ell), key=lambda x: x[one])
I'd like to point to the operator module which allows you to write the
above as:
min(enumerate(ell), key=operator.itemgetter(one))
--
Antoon Pardon.
More information about the Python-list
mailing list