| сян ли EvalFormulae 4241 | Ковалев Григорий, 524 группа EvalFormulae 3788 | ||||
|---|---|---|---|---|---|
| f | 1 | import re | f | 1 | import re |
| 2 | 2 | ||||
| 3 | def evalform(formula, *args): | 3 | def evalform(formula, *args): | ||
| t | 4 | names = sorted(set(re.findall('[A-Za-z]+', formula))) | t | 4 | vars = sorted(set(re.findall('[a-zA-Z_]\\w*', formula))) |
| 5 | local_vars = {name: value for name, value in zip(names, args)} | 5 | context = {var: arg for var, arg in zip(vars, args)} | ||
| 6 | return eval(formula, {}, local_vars) | 6 | return eval(formula, {}, context) | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||