round numbers in an array without importing Numeric or Math? - SOLVED, sort of
Bernhard Herzog
bh at intevation.de
Wed May 17 08:28:07 EDT 2006
"Paul McGuire" <ptmcg at austin.rr._bogus_.com> writes:
> ... or if you prefer the functional approach (using map)...
>
> roundToInt = lambda z : int(z+0.5)
> Topamax = map( roundToInt, map( float, map(str, Topamax) ) )
>
> (Python also has a built-in round() function, but this returns floats, not
> ints - if that is okay, then just delete the lambda definition, and replace
> roundToInt with round.)
Your roundToInt behaves differently from round for negative numbers:
>>> roundToInt(-0.6)
0
>>> int(round(-0.6))
-1
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://skencil.org/
Thuban http://thuban.intevation.org/
More information about the Python-list
mailing list