Integer From A Float List?!?

Discussion in 'Python' started by andrea_gavana@tin.it, Mar 5, 2005.

  1. Guest

    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.
     
    , Mar 5, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    7
    Views:
    6,269
    Roedy Green
    May 10, 2004
  2. bd
    Replies:
    0
    Views:
    635
  3. Replies:
    0
    Views:
    279
  4. Bill Mill

    Re: Integer From A Float List?!?

    Bill Mill, Mar 4, 2005, in forum: Python
    Replies:
    1
    Views:
    3,690
    George Sakkis
    Mar 5, 2005
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,561
    James Kanze
    Oct 8, 2009
Loading...

Share This Page