Tuenti ejercicio 1
This file contains 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
te lo acabo de forkear con trucos de perro viejo XD