Proposal: min(None, x) and max(None, x) return x
Chad Netzer
cnetzer at mail.arc.nasa.gov
Fri Nov 22 15:27:27 EST 2002
On Friday 22 November 2002 06:25, Eric Brunel wrote:
> 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)
My kludgey workaround goes something like this:
_xMax = []
for -whatever-:
-big calculation leading to a value of x-
_xMax.append( x )
_xMax = [max(xMax)]
xMax = _xMax[0]
Saves a line (and doesn't need to worry about None). And of course, there is
always the possibly evil:
_xMax = []
for -whatever-:
-big calculation leading to a value of x-
_xMax.append( x )
xMax = max(_xMax) #
--
Bay Area Python Interest Group - http://www.baypiggies.net/
Chad Netzer
cnetzer at mail.arc.nasa.gov
More information about the Python-list
mailing list