Created
July 10, 2013 04:40
-
-
Save Beyamor/5963522 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_operator(symbol): | |
return isinstance(symbol, basestring) | |
def to_infix(postfix): | |
stack = [] | |
for symbol in postfix: | |
if is_operator(symbol): | |
operand2 = stack.pop() | |
operand1 = stack.pop() | |
stack.append([operand1, symbol, operand2]) | |
else: | |
stack.append(symbol) | |
return stack[0] | |
print(to_infix([3, 4, 5, "*", "+"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment