[Python-ideas] Make max() stable
Terry Reedy
tjreedy at udel.edu
Sat Jan 18 01:48:55 CET 2014
On 1/17/2014 7:09 PM, Andrew Barnert wrote:
> On Jan 17, 2014, at 15:34, Terry Reedy <tjreedy at udel.edu> wrote:
>> Min and max are inherently functions of multisets, with order
>> irrelevant but duplicate values allowed.
I should have said a multiset of comparable objects.
> I'm not sure that's necessarily true. The maximal value of a sequence
> makes every bit as much sense as the maximal value of a set or
> multiset
A list of comparable objects *is* a multiset of comparable objects. So
is any iterable of comparable objects. Which is why 'iterable of
comparable objects' is the proper domain for max. Similar comments apply
to any commutative associative operator.
> For example, if I have
> a series of experiments at different times, the (time, value) pairs
> have an obvious meaningful order, and asking for max(experiments,
> key=itemgetter(1)) is a meaningful thing to do.
max((value,time) for time,value in experiments)
gives the lastest high value. In general
max((val,i) for i,val in enumerate(iterable))
does the same.
If max gave the last maximum, it would be trickier to get the first
maximum, just as it is now to get the last minimum.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list