
Little test:
from itertools import combinations [id(v) for v in combinations(range(10), 1)] [140347856824784, 140347856101328, 140347856824784, 140347856101328, 140347856824784, 140347856101328, 140347856824784, 140347856101328, 140347856824784, 140347856101328] for v in combinations(range(10), 1): ... print(id(v)) ... 140347856706048 140347856824784 140347856706048 140347856824784 140347856706048 140347856824784 140347856706048 140347856824784 140347856706048 140347856824784
As you can see, the temporary object is not immediately removed, but it's removed after the reassignment. This was not very clear in Eric Wieser's example, since the size of the iterable was too short. I suppose Python, as Andrew Barnert suggested, can immediately discard the old object for comprehensions. But, really, I don't see a very big advantage. Only if the element of the iterable are __really__ big it could be a little improvement, but I suppose it will slow down all the other comprehensions (as Barnert already pointed out).