[Python-Dev] RE: list comprehensions (was parsers and compilers for 2.0)

esr@thyrsus.com esr@thyrsus.com
Mon, 14 Aug 2000 18:57:18 -0400


Greg Ewing <greg@cosc.canterbury.ac.nz>:
> Two reasons why list comprehensions fit better in Python
> than the equivalent map/filter/lambda constructs:
> 
> 1) Scoping. The expressions in the LC have direct access to the
>    enclosing scope, which is not true of lambdas in Python.

This is a bug in lambdas, not a feature of syntax.
 
> 2) Efficiency. An LC with if-clauses which weed out many potential
>    list elements can be much more efficient than the equivalent
>    filter operation, which must build the whole list first and
>    then remove unwanted items.

A better argument.  To refute it, I'd need to open a big can of worms
labeled "lazy evaluation".
-- 
		<a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a>

Freedom, morality, and the human dignity of the individual consists
precisely in this; that he does good not because he is forced to do
so, but because he freely conceives it, wants it, and loves it.
	-- Mikhail Bakunin