How to efficiently proceed addition and subtraction in pythonlist?

Fredrik Lundh fredrik at pythonware.com
Tue Sep 19 08:42:41 EDT 2006


Steve Holden wrote:

> And statements like that are probably going to annoy me ;-)
>
>  >>> t = timeit.Timer("b = map(lambda x: x-1, a)", setup="a=[1,2,3]")
>  >>> t.timeit()
> 2.4686168214116599
>  >>> t = timeit.Timer("b = [x-1 for x in a]", setup="a=[1,2,3]")
>  >>> t.timeit()
> 0.9930245324475635
>  >>>

And now someone's probably reading this and thinking that list comprehensions
are *always* faster than "map"...

</F> 






More information about the Python-list mailing list