round numbers in an array without importing Numeric or Math? - SOLVED, sort of
Scott David Daniels
scott.daniels at acm.org
Tue May 16 18:27:29 EDT 2006
Paul McGuire wrote:
> ... or if you prefer the functional approach (using map)...
>
> roundToInt = lambda z : int(z+0.5)
> Topamax = map( roundToInt, map( float, map(str, Topamax) ) )
Somehow, the list comprehension looks simpler and clearer to me:
Topamax = [int(float(uni) + .5) for uni in Topamax]
I really dislike lines like:
roundToInt = lambda z : int(z+0.5)
You've already chosen a name, but you'd rather write in the lisp style.
def roundToInt(z):return int(z+0.5)
takes all of _one_ more character.
I also don't understand why you convert to string from unicode in:
... map(str, Topamax) ) )
float works on all string types (including unicode), and will accept
some non-ASCII digit values.
--
-Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list