[Python-ideas] Make max() stable

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jan 18 09:25:23 CET 2014


Devin Jeanpierre wrote:
> In a language like C++, you if min and max had the property specified
> by the OP, you might do:
> 
> x = min(a, b);
> y = max(a, b);
> 
> And then x is the smallest, and y is the other one

With Python's current definition of max(), you can
get that effect using

x, y = min(a, b), max(b, a)

So max() *does* respect the order of its operands;
it's just that the order it respects may not be obvious
unless you're Dutch.

-- 
Greg


More information about the Python-ideas mailing list