Re:PEP 572: Python assignment expressions has been accepted
by eswoo on Thursday July 12, 2018 @08:21PM
(#17519674)
It needs to be
[bar(foo(y)) for y in (z for z in stuff if foo(z))]
(etc.) though, since `bar` takes as input the output of `foo`. This leads to the objectionable duplicate calls to `foo`, hence the new assignment expressions.I like Dunnorandom's
[bar(x) for x in map(foo, stuff) if x]
best for a correct result using existing syntax, or [bar(x) for y in (foo(x) for x in stuff) if y]
if you don't like `map`.
Overall, I think I agree with you - the new syntax in PEP572 might be handy, but it isn't necessary and I would say that the cognitive overhead of encountering yet another syntax doesn't justify the benefit, much less the technical overhead for the interpreter.