A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-May/153289.html below:

[Python-Dev] PEP 572: Assignment Expressions

[Python-Dev] PEP 572: Assignment Expressions [Python-Dev] PEP 572: Assignment ExpressionsSteven D'Aprano steve at pearwood.info
Tue May 1 03:00:53 EDT 2018
On Tue, May 01, 2018 at 11:04:55AM +1000, Chris Angelico wrote:

> To be fair, I don't see many people replacing "x = 1" with "for x in
> [1]: pass". Even though it IS going to have the same effect. :-)

Aside from the pass, that is precisely one of the current work-arounds 
for lack of binding-expressions inside comprehensions:

    # inefficient, and wrong when f(x) has side-effects
    [f(x) for x in iterable if f(x) > 1]

    # what we'd like
    [y for x in iterable if (y := f(x)) > 1]

    # a work-around
    [y for x in iterable for y in [f(x)] if y > 1]


I think that's even in your PEP, isn't it?



-- 
Steve
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4