|   | 1 |  initial version  | 
Here is an answer using the list command and some list comprehensions.
var('x y')
R.<x,y>=PolynomialRing(RR)
q=x^2*y^2+x+x^2*y+y^2
terms=list(q)
ans=[t[1] for t in terms if (t[1].degree(x) % 2)==0 and (t[1].degree(y) % 2==0)]
sum(ans)
|   | 2 |  No.2 Revision  | 
Here is an answer using the list command and some list comprehensions.
var('x y')
R.<x,y>=PolynomialRing(RR)
q=x^2*y^2+x+x^2*y+y^2
terms=list(q)
ans=[t[1] ans=[t[0]*t[1] for t in terms if (t[1].degree(x) % 2)==0 and (t[1].degree(y) % 2==0)]
sum(ans)
This will also keep the coefficients.
 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.