Integer From A Float List?!?

A

andrea_gavana

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top