Author rhettinger
Recipients eric.smith, miss-islington, paul.moore, rhettinger, sreedevi.ha, steven.daprano, terry.reedy
Date 2020-09-29.16:18:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601396301.49.0.621233851152.issue41774@roundup.psfhosted.org>
In-reply-to
Content
> 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
History
Date User Action Args
2020-09-29 16:18:21rhettingersetrecipients: + rhettinger, terry.reedy, paul.moore, eric.smith, steven.daprano, miss-islington, sreedevi.ha
2020-09-29 16:18:21rhettingersetmessageid: <1601396301.49.0.621233851152.issue41774@roundup.psfhosted.org>
2020-09-29 16:18:21rhettingerlinkissue41774 messages
2020-09-29 16:18:20rhettingercreate