No swap function in Python?

Ben Caradoc-Davies bencd at bigfoot.com
Wed May 30 18:17:56 EDT 2001


On Wed, 30 May 2001 16:57:41 +0200, Bolton, Gawain [ADC:4808:EXCH] 
<boltong at europem01.nt.com> wrote:
[snip]
>Which made me think that a swap could be done like this:
>
>(a,b) = (b,a)
>
>But I'm not completely convinced doing this is safe.

It is safe and idiomatic. This is the canonical way of swapping the bindings of
variables.

>Finally, if the behaviour is guaranteed, is this an efficient
>way of doing a swap?

Efficient of what? Read the Camel book. :->

This is the simplest way to represent the operation and therefore the most
efficient use of author, maintainer, and porter time (the most scarce
resource).

-- 
Ben Caradoc-Davies <bencd at bigfoot.com>



More information about the Python-list mailing list