Skip to content

Instantly share code, notes, and snippets.

@lakinwecker
Last active March 4, 2017 02:26
Show Gist options
  • Save lakinwecker/7437b0ace6d7c0ffcdf4259e39284561 to your computer and use it in GitHub Desktop.
Save lakinwecker/7437b0ace6d7c0ffcdf4259e39284561 to your computer and use it in GitHub Desktop.
from operator import *
lookup = { '-': sub, '+': add, '*': mul, '/': truediv, '^': pow}
def lwe(e):
for ops in ['+-', '/*', '^']:
i = max([e.rfind(c) for c in ops])
if i != -1: return lookup[e[i:i+1]](lwe(e[:i]), lwe(e[i+1:]))
return float(expr)
print(lwe(input("> ")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment