map is useless!

rantingrick rantingrick at gmail.com
Sun Jun 6 11:16:02 EDT 2010


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*




More information about the Python-list mailing list