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).
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5YKUG4LZYFFUYYYWXSDFAZP43A3VRKVO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to