harsh harsh - 1 year ago 84
Python Question

How to find all terms in an expression in Sympy

I have an expression as:


What I need is a list that contain the terms in this expression.

[1/(x+1), 4*x/(x-1), 3, -4*x**2 , 10*x**2]

update: It should not collect like terms. Therefore the list should have -4*x** 2 and 10*x** 2 separately and not 6*x**2 after collecting like terms.

Answer Source

Based on the question and comments, if you can get the expression as a string, you can do something like this if you want to avoid term collection.

(sympify("1/(x+1)+4*x/(x-1)+3-4*x**2+10*x**2", evaluate=False)).args

this will return all the terms without collecting like terms.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download