Trying to restate the proposal, somewhat more formal following Random832
and Paul's suggestion.

I only speak about the single star.
---

*The suggested change of syntax:*

    comprehension ::=  starred_expression comp_for

*Semantics:*

(In the following, f(x) must always evaluate to an iterable)

1. List comprehension:

    result = [*f(x) for x in iterable if cond]

Translates to

    result = []
    for x in iterable:
        if cond:
            result.extend(f(x))

2. Set comprehension:

    result = {*f(x) for x in iterable if cond}

Translates to

    result = set()
    for x in iterable:
        if cond:
            result.update(f(x))

3. Generator expression:

    (*f(x) for x in iterable if cond)

Translates to

    for x in iterable:
        if cond:
            yield from f(x)

Elazar
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to