Skip to content Skip to sidebar Skip to footer

Convert Xy To X*y?

I am working on a project where user enters the input in the form of xy or 2x or 2ab but sympy is not able to understand that, i want to convert them into x * y, 2 * x, 2 * a * b r

Solution 1:

sympy is actually able to understand that. You need to use parsing to help for it:

from sympy.parsing.sympy_parser import parse_expr
from sympy.parsing.sympy_parser import standard_transformations,\
implicit_multiplication_application
transformations = (standard_transformations +
    (implicit_multiplication_application,))
print(parse_expr("xy", transformations=transformations))

Output: x*y

Post a Comment for "Convert Xy To X*y?"