[Tutor] In-place expansion of list members... possible?
Kent Johnson
kent37 at tds.net
Sat Nov 10 05:43:10 CET 2007
Ricardo Aráoz wrote:
> Kent Johnson wrote:
>> or use slice assignment:
>> tmpSegs[:] = [ seg.split(self.ElemSep) for seg in tmpSegs ]
>
> Won't the slice assignment create a new list and then assign it to the
> old list (which the OP is trying to avoid)?
Yes, it will, thanks! You can assign a generator expression to the list:
tmpSegs[:] = ( seg.split(self.ElemSep) for seg in tmpSegs )
I don't know if that creates a temp list or assigns directly into the
old list though. At the byte-code level at least it seems to assign the
iterator to the slice.
Kent
More information about the Tutor
mailing list