For review: PEP 308 - If-then-else expression

Erik Max Francis max at
Sat Mar 1 00:25:39 CET 2003

"Chermside, Michael" wrote:

> Just want to express disagreement. I find listcomps to be EXTREMELY
> readable, and to improve the readability of the programs that I
> write. I'm not criticizing your opinions, of course, but I didn't
> want readers to think that EVERYONE dislikes listcomp syntax.

Indeed.  A Python newbie asked me a question about interpreting some
code (I believe it was some code he ran somewhere to run the
coins-out-of-a-bag probability problem; he didn't say which variant). 
He came across a list comprehension, which was made even harder to
understand since it it involved generating a list of lists (he hadn't
even been familiar with the + operator used to concatenate lists).  When
I explained to him what it meant, I then showed him the general form of
what it can do, then showed him some more readable examples, like

	name = [ for x in people]

At first he remarked how strange that was, within a few minutes he was
impressed by its power, and then by the end of the discussion he said,
"Well, that's one more reason for me to prefer Python to Perl."

 Erik Max Francis / max at /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ That it will never come again is what makes life so sweet.
\__/ Emily Dickinson
    WebVal /
 URL scanner, maintainer, and validator in Python.

More information about the Python-list mailing list