Proposal: min(None, x) and max(None, x) return x

Eric Brunel eric.brunel at pragmadev.com
Fri Nov 22 09:25:07 EST 2002


Hi all,

I quite often find myself doing things like:

xMax = None
for -whatever-:
  -big calculation leading to a value of x-
  if xMax is None:
    xMax = x
  else:
    xMax = max(x, xMax)

or the same kind of stuff with min, of course.

So I told myself: wouldn't it be great if max(None, x) or min(None, x) 
always simply returned x? So I could just write:

xMax = None
for -whatever-:
  -big calculation leading to a value of x-
  xMax = max(x, xMax)

Okay, it only saves 3 lines, but I personally find it quite natural... In 
addition, today, min(None, x) and max(None, x) work, but have strange 
results: as far as I can see, min(None, x) is always None and max(None, x) 
is always x, but this behaviour isn't documented.

Opinions anyone?
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list