[Python-ideas] An alternative to PEP 572's Statement-Local Name Bindings
Chris Angelico
rosuav at gmail.com
Sun Mar 4 23:04:41 EST 2018
On Mon, Mar 5, 2018 at 2:49 PM, Mike Miller <python-ideas at mgmiller.net> wrote:
> Yes, thanks:
>
> [ f(y), g(y) for x, h(x) as y in things ]
>
>
> Dyslexics untie!
:)
Hmm. The trouble here is that a 'for' loop is basically doing
assignment. When you say "for x, h(x) as y in things", what Python
does is (simplified):
_it = iter(things)
while not StopIteration:
x, (h(x) as y) = next(_it)
... loop body ...
So what you're asking for is something that doesn't behave like an
assignment target, but just does its own assignment. Bear in mind,
too, that "x = next(_it)" is very different from "x, = next(_it)";
which one is "x, (h(x) as y) = next(_it)" more like?
ChrisA
More information about the Python-ideas
mailing list