Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Integer From A Float List?!?

Reply
Thread Tools

Integer From A Float List?!?

 
 
andrea_gavana@tin.it
Guest
Posts: n/a
 
      03-05-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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
operator== (float, float) Jukka Lehtonen C++ 5 08-05-2004 08:28 AM
need code to convert float format to internal java float format which is kept in 4 bytes integer Andy Java 7 05-10-2004 09:26 PM
static_cast<float>(a) versus float(a) Jim West C++ 4 01-16-2004 12:36 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments