Temporary variables in list comprehensions

Paul Rubin no.email at nospam.invalid
Mon Jan 9 16:16:25 EST 2017

Tim Chase <python.list at tim.thechases.com> writes:
>> result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)]
> As charmingly expressive as map() is, the wildly different behavior in
> py3 (it's a generator that evaluates lazily) vs py2 (it consumes the
> entire iterable in one go) leads me to avoid it in general,

Well, there's itertools.imap which maps lazily in py2.

More information about the Python-list mailing list