[Python-ideas] Make max() stable

Devin Jeanpierre jeanpierreda at gmail.com
Sat Jan 18 11:40:50 CET 2014


On Sat, Jan 18, 2014 at 12:12 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> These variations only are meaningful if a and b are different types
> with the same value, or the same type but different identities. Even if
> these variations are important, I don't think there is any inherent
> benefit to one over the other.

These variations are also important if a and b are just plain
different values, same type or no. This can happen if max/min are
passed a key function -- equality of a sort key doesn't mean the
values are interchangeable for all purposes

if x and y are strings with the same length, min(x, y, key=len) +
max(x, y, key=len) is something different in each of those helpfully
enumerated cases, and that's with a well behaved type and a
superficially OK looking expression.

That said, considering (as Greg points out) that all four variations
can be transformed into one another by rearranging the arguments to
min and max, I think it's pretty clear that there's nothing strongly
favoring any one of them, so on that (and the rest) I agree.

-- Devin


More information about the Python-ideas mailing list