[Python-ideas] add a list.swap() method

Jared Grubb jared.grubb at gmail.com
Mon Jun 29 18:57:47 CEST 2009

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.


More information about the Python-ideas mailing list