[Python-ideas] On evaluating features [was: Unpacking iterables for augmented assignment]

Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Tue Aug 28 12:37:09 EDT 2018


Chris Angelico writes:

 > When you have completely different variables, sure. But what if - like
 > in the swap example - they're the same variables?
 > 
 > a, b, c += b, c, a

Good point.

    a, b, c = a + b, b + c, c + a

is "good enough" for this particular case, I'd say, and has the
advantage that it immediately generalizes to mixed operations:

    a, b, c = a + b, b - c, c * a

I will say that the fact that neither of us has an immediate use case
in mind is really the point of my previous post.  Swaps frequently
come up in sorting algorithms and heap structure modifications.
Swapping alone might be enough to justify the destructuring
assignment.

Steve


More information about the Python-ideas mailing list