[Python-ideas] FW: Map-then-filter in comprehensions

Joseph Jevnik joejev at gmail.com
Tue Mar 8 14:07:51 EST 2016


I was going to write `with expr as name` but I felt that people might find
it too conficting with the other use of the `with` keyword. I personally
find that it reads very well. We could always go with a new keyword like:
`bind expr as name` but that seems pretty heavy. In defense of the `for
expr as name` proposal, it does match pretty closely to the nested for
statements in a comprehension.

On Tue, Mar 8, 2016 at 2:01 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Wed, Mar 9, 2016 at 5:57 AM, Joseph Jevnik <joejev at gmail.com> wrote:
> > If we were to translate this to python syntax we could have something
> like:
> > [r + 1 for n in range(1, 11) for n * 3 as r if r % 4 == 0]
> > There is no reason that the name binding needs to be a part of the
> predicate
> > expression, they can just be seperate clauses. I think the `for expr as
> > name` is nice because it matches the order that comprehensions over
> multiple
> > iterators are evaluated like: `[n for n in ns for m in ms]`.
>
> That's somewhat more appealing. Not enthused about "for expr as name";
> maybe "with expr as name"? Aside from not calling __enter__ and
> __exit__, it's the same kind of operation that a with block does. But
> the semantic difference isn't a good thing.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160308/5cca7305/attachment-0001.html>


More information about the Python-ideas mailing list