You could probably do this with something is the polynomial module, like http://docs.sympy.org/dev/modules/polys/reference.html#sympy.polys.polytools.Poly.as_dict