Integer From A Float List?!?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andrea_gavana@tin.it

    #1

    Integer From A Float List?!?

    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(in t, 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.

Working...