Код: Выделить всё
import math
equation = "5+5*10"
equation_segmented = ["5", "+", "5", "*", "10"]
equation = "(2*2)-5*(math.sqrt(9)+2)"
equation_segmented = ["(2*2)", "-", "5", "*", "(math.sqrt(9)+2)"]
equation = "(((5-3)/2)*0.5)+((2*2))*(((math.log(5)+2)-2))"
equation_segmented = ["(((5-3)/2)*0.5)", "+", "((2*2))", "*", "(((math.log(5)+2)-2))"]
Код: Выделить всё
import re
equation_segmented = re.split("([\+|\-|\*|\/]|\(.*\))", equation)
< /code>
Проблема здесь, однако, заключается в том, что она не учитывает соответствующие кронштейны.equation_segmented = re.split("([\+|\-|\*|\/])", equation)
Подробнее здесь: https://stackoverflow.com/questions/796 ... n-matching