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

alex23 wuwei23 at gmail.com
Thu Jun 25 09:00:58 CEST 2009


Kristján Valur Jónsson <krist... at ccpgames.com> wrote:
> The idea is to speed up the swapping of list elemenst so that
> a.swap(b)
> is equivalent to
> a[:], b[:] = b[:], a[:]
> but without all the overhead of creating slices, assigning them and so forth.

I think I'd use a mapping to hold the lists so I could do a straight
re-assignment:

 d['a'], d['b'] = d['b'], d['a']

Of course, all references to the lists would have to be brokered
through the mapping object, but I tend to find it easier to do so
anyway.



More information about the Python-ideas mailing list