Re: [Python-Dev] PEP 572: Assignment Expressions

May 1, 2018
7 a.m.
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
2580
Age (days ago)
2580
Last active (days ago)
0 comments
1 participants
participants (1)
-
Steven D'Aprano