on-internet
← Community

sympy parse/expand without alphabetical ordering

Stack Overflow ·

I'm trying to use sympy's to expand a simple arithmetic expression involving variable names (one of which is RECIST ) import sympy def _sympy_expand(expr): parsed = sympy.parsing.sympy_parser.parse_expr(expr) return str(sympy.expand(parsed)) tables = "idx + ohio * (idx + sex + recist)" _sympy_expand(tables) # 'idx*ohio + idx + ohio*recist + ohio*sex' Problem is that in my application, order of elements has meaning. That is what I wanted is to avoid lexical ordering and tables to be expanded to # "idx + ohio*idx + ohio*sex + ohio*recist" I've searched the doc but didn't found a solution; any hi

Comments

Sign in or sign up to comment and upvote.

No comments yet.