3 ms·
Ah yes, mea culpa, I misread your example as lambda x: x = x; do_thing(x) Rather than the: lambda x, x = x: do_thing(x) And yes, your example works, and
by Blikkentrekker 6y ago
Ah yes, mea culpa, I misread your example as
lambda x: x = x; do_thing(x)
Rather than the:
lambda x, x = x: do_thing(x)
And yes, your example works, and is functionally similar to my initial solution of using that function scope does exist by simply creating a function for no other reason than to call it to create a new scope.
That doesn't stop that both examples are ugly hacks needed to solve a problem with the language that most languages do not have. And despite your calling it idiomatic, I have never seen your example in the wild and it is, frankly, simply a hack that few programmers that haven't been explicitly taught this trick would quickly see the intend behind.