Scott,

this was a really clever catch, but I don't agree with the solution.
The problem is your assumption of how zip/izip _must_ work.  I don't
think there is any contract that states that they will always advance
the first argument first and the second argument second... that is an
implementation detail (the end result, ignoring iterator state, is the
same regardless of the order in which you advance things).  Given this,
I think using izip is simply a bad idea.

How about something like this:

    def __add__(self, other):
        rcoefs1 = reversed(self.coefs)
        rcoefs2 = reversed(other.coefs)
        minlen = min(len(rcoefs1), len(rcoefs2))
        coefs = [rcoefs1.next()+rcoefs2.next() for i in xrange(minlen)]
        coefs.extend(rcoefs1)
        coefs.extend(rcoefs2)
        if coefs[-1] != 0:
            return Polynomial(reversed(coefs), False, False)
        else:
            return Polynomial(reversed(coefs), False)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to