On Jun 6, 2010, at 5:16 PM, rantingrick wrote:
Everyone knows i'm a Python fanboy so nobody can call me a troll for
this...

Python map is just completely useless. For one it so damn slow why
even bother putting it in the language? And secondly, the total "girl-
man" weakness of lambda renders it completely mute!

Ruby has a very nice map

[1,2,3].map{|x| x.to_s}

Have not done any benchmarking but far more useful from the
programmers POV. And that really stinks because map is such a useful
tool it's a shame to waste it. Here are some test to back up the rant.


import time
def test1():
        l = range(10000)
        t1 = time.time()
        map(lambda x:x+1, l)
        t2= time.time()
        print t2-t1


def test2():
        l = range(10000)
        t1 = time.time()
        for x in l:
                x + 1
        t2 = time.time()
        print t2-t1


test1()
0.00200009346008
test2()
0.000999927520752
def test3():
        l = range(10000)
        t1 = time.time()
        map(str, l)
        t2= time.time()
        print t2-t1


def test4():
        l = range(10000)
        t1 = time.time()
        for x in l:
                str(x)
        t2= time.time()
        print t2-t1


test3()
0.00300002098083
test4()
0.00399994850159


So can anyone explain this poor excuse for a map function? Maybe GVR
should have taken it out in 3.0?  *scratches head*

Use list comprehension. It's nicer than Ruby's map:

[x.to_s for x in 1, 2, 3]

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to