Python3: on removing map, reduce, filter

Robert Kern rkern at ucsd.edu
Sun Jan 9 16:06:19 CET 2005


Andrey Tatarinov wrote:

> anyway list comprehensions are just syntaxic sugar for
> 
>  >>> for var in list:
>  >>>     smth = ...
>  >>>     res.append(smth)
> 
> (is that correct?)
> 
> so there will be no speed gain, while map etc. are C-implemented

It depends.

Try

   def square(x):
       return x*x
   map(square, range(1000))

versus

   [x*x for x in range(1000)]

Hint: function calls are expensive.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the Python-list mailing list