[Python-ideas] Make max() stable
Devin Jeanpierre
jeanpierreda at gmail.com
Sat Jan 18 08:40:49 CET 2014
On Fri, Jan 17, 2014 at 5:35 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> Is there an example of an actual problem that stability of min and max would
> make easier to solve?
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, and it's simple and
easy and less code than an if statement. I suspect this is where the
desire comes from.
In Python, of course, you do x, y = sorted([a, b])
-- Devin
More information about the Python-ideas
mailing list