From: rantingrick on
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*

From: James Mills on
On Mon, Jun 7, 2010 at 1:16 AM, rantingrick <rantingrick(a)gmail.com> wrote:
> So can anyone explain this poor excuse for a map function? Maybe GVR
> should have taken it out in 3.0?  *scratches head*

Let me get this straight... You're complaining about some trivial
code you've written and a 0.002 or less execution time ?

I must be missing something!

--James
From: Roald de Vries on
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]

From: Duncan Booth on
rantingrick <rantingrick(a)gmail.com> wrote:

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

Do you realise that you don't have to use lambda? If you need more than a
single expression just create a named function.
From: Alain Ketterlin on
rantingrick <rantingrick(a)gmail.com> writes:

> Python map is just completely useless. [...]

>>>> 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():

Well, not building the resulting list saves some time. But even if you
do r.append(x+1) map appears to be slower...

Try this:

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

I've not used map since I learned about list comprehensions.

-- Alain.