[Python-ideas] add a list.swap() method
Scott David Daniels
Scott.Daniels at Acm.Org
Tue Jun 30 00:22:25 CEST 2009
Jared Grubb wrote:
>
> On 25 Jun 2009, at 17:41, Steven D'Aprano wrote:
>> What you really want is a fast way of initialising a list, given another
>> list. That was your use-case, after all. Swapping the contents is just
>> one particular implementation of that fast-initialise.
>
> FWIW, this use case really sounds a lot like rvalue references, a new
> feature being added to the new C++0x standard. The basic idea is that,
> for efficiency reasons, you want to be able to "sink" the contents an
> object and leave the object in a destructable (but not necessarily
> valid) state.
>
> This would be a tough (and probably inappropriate?) feature in Python,
> but I mention it because the concept might provide further
> context/justifications/trade-offs/ideas for what is being discussed here.
The OP might consider code that does the swap if the refcount is 1,
otherwise does something akin to recur(arg.copy()) (which _will_ have
a refcount of 0).
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-ideas
mailing list