Augmented Assignment question

Tim Lesher tim at lesher.ws
Wed Jul 16 22:17:47 EDT 2003


Doug Tolton <dtolton at yahoo.com> wrote in message news:<215bhv0bnkn13eivh0s64ic5ml8obpgfg7 at 4ax.com>...
> This solution strikes me as inelegant and ugly.  Is there a cleaner
> way of accomplishing this?

The problem is this:  performing addition of tuples is concatenation,
not addition of the elements.  If you try to decompose the augmented
addition into an addition and an assignment, you get a tuple that is
(in your case) the concatenation of the two 3-tuples, or a 6-tuple,
which can't unpack into a 3-tuple.

That said, for some definition of "cleaner", you could do:
def accumulate(i,j):
    return map(int.__add__, i, j)

// loop
    i,j,k = accumulate((i,j,k), fn())




More information about the Python-list mailing list