I deal with polynomials of varying number of variables, and need a uniform way to iterate over their terms. What works for multivariate polynomials does not for univariate ones, and vice versa. Is there a uniform approach here?
Example:
sage: R1.<x,y> = QQ[]
sage: R2.<z> = QQ[]
sage: P = x + 2*y + x*y + 3
sage: Q = z + 5
sage: for c,t in P: print c,t
1 x*y
1 x
2 y
3 1
sage: for c,t in Q: print c,t
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-26-3ef1c7d76c79> in <module>()
----> 1 for c,t in Q: print c,t
ValueError: need more than 1 value to unpack