Swapping values of two variables

Grant Edwards grante at visi.com
Fri Jan 30 06:29:44 CET 2009


On 2009-01-30, MRAB <google at mrabarnett.plus.com> wrote:

>> What is the minimum amount of extra memory required to exchange two
>> 32-bit quantities? What would be the pseudocode that achieves this
>> minimum?
>
> x ^= y
> y ^= x
> x ^= y
>
> This is really only of use when working in assembly language.

And rarely then. ;)

[Readability counts everywhere.]

-- 
Grant




More information about the Python-list mailing list