map is useless!

Carl Banks pavlovevidence at gmail.com
Sun Jun 6 20:57:00 EDT 2010


On Jun 6, 8:16 am, rantingrick <rantingr... at gmail.com> wrote:
> Everyone knows i'm a Python fanboy so nobody can call me a troll for
> this...

1. I don't remember you so I don't know if you're a Python fanboy or
not
2. If you act like a troll I'll call you one even if you are Python
fanboy

Actually, your post only came off as slightly trollish, so you have
that.


> 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*

Since you claim to be a Python Fanboy, you probably know that you can
type "import this" at a Python prompt, and it brings up a list of
principles that guide the design of the language.

Tell me, do you see "Fast is better than slow" in that list?  No?
Well that's your answer.

(The technical answer is that map isn't slow, function call overhead
is.)


Carl Banks



More information about the Python-list mailing list