swapping (was Re: Changing class membership)
matthias.oberlaender at daimlerchrysler.com
matthias.oberlaender at daimlerchrysler.com
Mon Oct 9 03:27:40 EDT 2000
Thanks a lot for the "lesson". Yes, tuples truly make it much more elgant.
In <8rkt6o03g8 at news2.newsguy.com> "Alex Martelli" wrote:
>
> In general, the Python swap idiom is
> a, b = b, a
> or, of course:
> a.something, b.whatever = b.whatever, a.something
> etc, although the idiom of
> temp = a
> a = b
> b = temp
> (mutuated from languages without tuple packing/unpacking
> abilities:-) will also work, of course (less elegant, IMHO).
>
>
> Alex
>
>
>
>
-- Matthias
More information about the Python-list
mailing list