Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def complex_evaluation(tokens):
- brackets = ["(", "[", "{", ")", "]", "}"]
- bracketsclose = [")", "]", "}"]
- bracketsopen = ["(", "[", "{"]
- brackpos = []
- for i in range(len(tokens)):
- if tokens[i] in brackets:
- brackpos.append([tokens[i], i])
- while len(brackpos) != 0:
- last = brackpos[0][1]
- for i in brackpos:
- if i[0] in bracketsclose:
- x = simple_evaluation(tokens[last + 1:i[1]])
- del tokens[last:i[1] + 1]
- tokens.insert(last, x)
- last = i[1]
- print(tokens)
- complex_evaluation([2, "^", "[", 4, "*", "(", 4, "+", 5, ")", "]", "/", 4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement