|   | 1 |  initial version  | 
Symbolics have a method .poly:
sage: var('x,y')
(x, y)
sage: p = x*y + x^2*y^2
sage: p.poly(x)
x^2*y^2 + x*y
sage: p.poly(x).coefficients()
[[y, 1], [y^2, 2]]
Multivariate polynomial rings have a method .polnomial()
sage: A.<x,y> = QQ[]
sage: p = x*y + x^2*y^2
sage: p.polynomial(x)
y^2*x^2 + y*x
sage: p.polynomial(x).list()
[0, y, y^2]
Both methods collect only with respect to one variable, so you may need to iterate.
 Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.
 
                
                Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.