First possible raw solution:
from operator import add, sub, mul, div, neg
def evaluate(expr):
if isinstance(expr, list):
fun, ops = expr[0], expr[1:]
return fun(*map(evaluate, ops))
else:
return expr
example = [add, [add, [sub, 5, 4], [mul, 3, 2]], [neg, 5]]
print
I'm trying to create a recursive function to evaluate the expressions
within a list. The function uses eval() to evaluate the list. Like a
lisp interpreter but very limited.
What I'm looking for is a function to recursively traverse the list and
provide answers in place of lists, so that ...
E