Do you know if you need all thees terms? Is there any case where you would want to use one of the factors that didn't have all the factors with y? So, if, for example, `h(x,y)=x*y*(y+1)`, if there is any case you'd want to use just `g(y)=y+1` rather than `g(y)=y*(y+1)`?

If not, you can pull out the terms with list comprehension as `Mul(*[term for term in factors if term.has(y) and not term.has(x) and term.is_algebraic_expr(y)])