Integer From A Float List?!?

andrea_gavana at tin.it andrea_gavana at tin.it
Sat Mar 5 07:34:04 EST 2005


Hello NG,

    probably because I still have Python 2.3.4, these are the results I'm
getting:


C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints
= m
ap(int, floats)"
1000 loops, best of 3: 398 usec per loop

C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints
= [
int(x) for x in floats]"
1000 loops, best of 3: 820 usec per loop

C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints
= [
]" "for x in floats: ints.append(int(x))"
1000 loops, best of 3: 932 usec per loop

C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" -s
"from
itertools import starmap, izip" "ints = list(starmap(int, izip(floats)))"
1000 loops, best of 3: 513 usec per loop


So, the last (very smart) solution, works slightly slower on my PC wrt the
first solution. I don't know really what has changed in Python 2.4... At
the moment I cannot switch to 2.4 because some site-packages I use are still
not updated to Python 2.4.

Anyway, thanks to you all for your smart suggestion. It is really a nice
newsgroup.

Andrea.




More information about the Python-list mailing list