Skip to content

Instantly share code, notes, and snippets.

@zigzackey
Created March 30, 2016 18:49
Show Gist options
  • Save zigzackey/4ae20ca01328cfd544b3d4f3d46b7221 to your computer and use it in GitHub Desktop.
Save zigzackey/4ae20ca01328cfd544b3d4f3d46b7221 to your computer and use it in GitHub Desktop.
def push(x):
global stack
stack.append(x)
def pop():
global stack
ret = stack.pop()
return ret
ope = {"+": lambda a, b: b + a,
"-": lambda a, b: b - a,
"*": lambda a, b: b * a}
if __name__ == '__main__':
stack = []
for c in input().split():
if c in ope:
push(ope[c](pop(), pop()))
else:
push(int(c))
print(" ".join(map(str, stack)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment