[Python-Dev] comprehension abbreviation (was: Adding any() and all())

Gareth McCaughan gmccaughan at synaptics-uk.com
Mon Mar 14 10:57:47 CET 2005

> - Before anybody asks, I really do think the reason this is requested
> at all is really just to save typing; there isn't the "avoid double
> evaluation" argument that helped acceptance for assignment operators
> (+= etc.), and I find redability is actually improved with 'for'.

I'd like it, and my reason isn't "just to save typing".
There are two reasons.

  1 Some bit of my brain is convinced that [x in stuff if condition]
    is the Right Syntax and keeps making me type it even though
    I know it doesn't work.

  2 Seeing [x for x in stuff if condition] triggers my internal
    duplicated-stuff alarm, and it's distracting, in the same sort
    of way as it's distracting in C or C++ seeing

        Thing thing = new Thing();

    with the type name appearing three times.

Incidentally, while it's quite true that you only save 4 characters
if you use "x" for your variable name, some of us do sometimes like
to use something more informative even as a very local loop-index
variable (which is what this basically is).


More information about the Python-Dev mailing list