[Python-ideas] Accessing the result of comprehension's expression from the conditional

Stephen J. Turnbull stephen at xemacs.org
Sun Jun 21 08:10:13 CEST 2009


Lie Ryan writes:

 > The proposal enables comprehension to become filter+map+filter,
 > map+filter, filter+map, or map-only; eliminating the redundant map in
 > (map+filter)+(map+filter).

The problem with the proposal is that that is *all* it does.  I don't
see how you plan to disambiguate in cases where the desired operation
"really is" (map+filter)+(map+filter).  So what you're stuck at is "I
want this one operation to be a one-liner."  The reply to that is "not
every two-line function needs to have special syntax."

Unless you can generalize this proposal to handle more general lambdas
in a beautiful and Pythonic way, you've already been offered two
obvious and nice ways to do it, and another obvious way that is an
"ugly" mixed metaphor.  All of the other idioms *do* generalize.  We
just spent several years de-cluttering Python 3, it's too soon to
start cluttering it up again, no matter how beautiful it makes this
special case.

And I happen to think Ben's iterated generator comprehension is the
most beautiful of the lot.  YMMV of course but so does a that of a lot
of other people; getting a consensus for new syntax is going to be
impossible if you don't generalize the proposal.



More information about the Python-ideas mailing list