Temporary variables in list comprehensions
Lele Gaifax
lele at metapensiero.it
Thu Apr 6 14:07:57 EDT 2017
Piet van Oostrum <piet-l at pietvanoostrum.com> writes:
> It is a poor man's 'let'. It would be nice if python had a real 'let'
> construction. Or for example:
>
> [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)]
>
> Alas!
It would be nice indeed!
Or even
[(tmp, tmp + 1) for x in data
with expensive_calculation(x) as tmp
if tmp is not None]
that fits the usual "with" syntax.
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it | -- Fortunato Depero, 1929.
More information about the Python-list
mailing list