3 ms·
In the generator case you can define a poor man's let like this: def let(x): yield x And use it by "iterating": ... for x in range(1, 101
by loqi 13y ago
In the generator case you can define a poor man's let like this:
def let(x):
yield x
And use it by "iterating":
...
for x in range(1, 101)
for divisible_by_5 in let(x % 5 == 0)
Still not as nice as having actual syntax for it.
- piinbinary 13y agoYou can also hack the with statement to get a let block: import contextlib @contextlib.contextmanager def let(*values): yield values with let(1, 2, 3) as (a, b, c): print(a, b, c)