How to find all terms in an expression in Sympy

后端 未结 3 1022
旧巷少年郎
旧巷少年郎 2021-02-14 12:16

I have an expression as: 1/(x+1)+4*x/(x-1)+3-4*x**2+10*x**2

What I need is a list that contain the terms in this expression.
i.e. [1/(x+1), 4*x/(x

3条回答
  •  星月不相逢
    2021-02-14 12:31

    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.

提交回复
热议问题