[Tutor] List comprehension

Jeff Shannon jeff@ccvcorp.com
Wed, 23 Jan 2002 09:53:28 -0800


> "Glen Wheeler" <wheelege@hotmail.com> wrote:
>

> > Python goes through great pains of saying that statements cannot
> > be used in expressions; assignment being the largest 'pain' for many
> > coming to Python.
> >
> > But here come list comprehession where you can now the syntax and
> > semantics similar to 'for' and 'if' statements, with the keywords,
> > inside an expression.
> >
>
>   Just for the record, I also think that list comprehensions confuse many
> people with their contradictory nature.  I personally quite enjoy using map,
> reduce and filter but list comprehensions seem to go against the nature of
> python.

FWIW, my personal experience is exactly the opposite.  List comprehensions may be
exceptions to some of the normal rules of Python syntax, but I can look at them and
figure out what they mean--they are close enough to English to be able to reason out.
Map and filter are fine by themselves, but they pretty much require using lambdas, and
I have *never* been able to wrap my mind around lambda syntax--my brain consistently
core-dumps as soon as I run into one.  ;)

In this case, I prefer something that's inconsistent but somewhat intuitive, to
something that's somewhat consistent but is totally counterintuitive.

(And I'm sure that someone will argue that lambdas aren't counterintuitive, but that's
how I, and apparently more than a few others, have always found them.)

Jeff Shannon
Technician/Programmer
Credit International