Панферов Виктор EvalFormulae 8535 | Илья Федоров, 617 группа EvalFormulae 8138 | ||||
---|---|---|---|---|---|
f | 1 | import re | f | 1 | import re |
2 | 2 | ||||
3 | def evalform(formula, *args): | 3 | def evalform(formula, *args): | ||
t | 4 | vars = sorted(set(re.findall('[a-z]\\w*', formula))) | t | 4 | vars = sorted(set(re.findall('\\b[a-zA-Z_]\\w*\\b', formula))) |
5 | vals = {k: v for k, v in zip(vars, args)} | 5 | var_dict = {k: v for k, v in zip(vars, args)} | ||
6 | return eval(formula, {}, vals) | 6 | return eval(formula, {}, var_dict) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|