◐ Shell
clean mode source ↗

Message 377673 - Python tracker

> If space is not an issue, the list comprehension may be fastest.

I think there is still a misunderstanding here.  The generator variant does not save space.  It uses slightly *more* space than the list variant.

The list_ass_slice()¹ function runs PySequence_Fast² on its input.  If the input is already a list or tuple, it is returned immediately.  If not, the iterator is run to exhaustion and a new list is built.  Either way, when the actual update occurs, the source will be a list or tuple.

¹ https://github.com/rhettinger/cpython/blob/master/Objects/listobject.c#L597
² https://github.com/rhettinger/cpython/blob/master/Objects/abstract.c#L2014