Skip to content

Instantly share code, notes, and snippets.

@Beyamor
Created July 10, 2013 04:40
Show Gist options
  • Save Beyamor/5963522 to your computer and use it in GitHub Desktop.
Save Beyamor/5963522 to your computer and use it in GitHub Desktop.
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