Separating line items is very simple. All elements have one character long, so you can directly iterate (or index) the string to get it. Or, if you want to be able to manipulate values, you can pass a string to the list constructor.
Here are some examples of how this might work:
string = "*-567" # iterating over each character, one at a time: for character in string: print(character) # prints one character from the string per line # accessing a specific character by index: third_char = string[2] # note indexing is zero-based, so 3rd char is at index 2 # transform string to list list_of_characters = list(string) # will be ["*", "-", "5", "6", "7"]
As for solving the equation, I think there are two approaches.
One of them is to make your function recursive so that each call evaluates one action or literal. This is a little complicated, since you should use only one function (it would be much easier if you could have a recursive helper function called with a different API than the main non-recursive function).
Another approach is to create a stack of values ββand operations that you expect to evaluate, taking only one iteration over the input string. This is probably easier given the limit of one function.
source share