f | def evalform(formula, *args): | f | def evalform(formula, *args): |
| var = '' | | var = '' |
| vars = set() | | vars = set() |
| for s in formula: | | for s in formula: |
| if s.isalpha(): | | if s.isalpha(): |
| var += s | | var += s |
t | | t | else: |
| elif var: | | if var: |
| vars.add(var) | | vars.add(var) |
| var = '' | | var = '' |
| if var: | | if var: |
| vars.add(var) | | vars.add(var) |
| vars = list(vars) | | vars = list(vars) |
| vars.sort() | | vars.sort() |
| vars_dict = {k: v for k, v in zip(vars, args)} | | vars_dict = {k: v for k, v in zip(vars, args)} |
| return eval(formula, vars_dict, None) | | return eval(formula, vars_dict, None) |