Skip to content

Instantly share code, notes, and snippets.

@javisantana
Forked from jorgebastida/gist:1023399
Created June 14, 2011 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javisantana/1024626 to your computer and use it in GitHub Desktop.
Save javisantana/1024626 to your computer and use it in GitHub Desktop.
Tuenti ejercicio 1
import re
from operator import add, mul, sub
import sys
ops = {'=': add, '@': sub, '#': mul }
r = '\^(.)\s*(\-?\d+)\s*(\-?\d+)\$'
def e(g):
g = g.groups()
return str(ops[g[0]](*map(int, g[1:])))
def parse(exp):
while '^' in exp:
exp = re.sub(r, e, exp)
return exp
if __name__ == '__main__':
for x in ' '.join(sys.argv[1:]).split('\n'):
print parse(x)
@javisantana
Copy link
Author

te lo acabo de forkear con trucos de perro viejo XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment