I have the following algorithm for parsing expressions in Python:
def parse(strinput): for operator in ["+-", "*/"]: depth = 0 for p in range(len(strinput) - 1, -1, -1): if strinput[p] == ')': depth += 1 elif strinput[p] == '(': depth -= 1 elif depth==0 and strinput[p] in operator:
(it can be found here: http://news.ycombinator.com/item?id=284842 )
It's hard for me to figure this out, since I don't find Python docs very useful for this situation. Can someone tell me which line: for operator in ["+-", "*/"]: means? I know its structure as for every string variable, which is an operator in an array of these two elements, but why is it written like this ["+ -, * /"]? How does Python separate this? At the first iteration, the "+ -" operator?
Any help would mean a lot. Thanks
source share