Example
input: [1, '+', [4, '*', [3, '*', 7]], '/', 2]
output: 43
input: [[1, '+', 3], '*', [2, '+', 4]]
output: 24
The number of nested lists is unknown
I'm not sure how to approach this. I've looked up other looping nested lists posts (iterate python nested lists efficiently & Python - Iterating through list of list) but they don't really work in this case since there's order of operations with the brackets.
I had thought of using recursion but I don't know how I would code it if it had like an enormous amount of nested loops and I'm not sure how to keep track of everything and finding the deepest list.
Thanks
EDIT: oops, sorry, didn't make it clear. Trying to essentially do a math expression based on what the list contains. It could contain * + - / and % and we have to do it based on order of operations.
EDIT2: How to apply order of operations and parenthesis priority to something like this?
import operator
ops = {'+': operator.add, '-': operator.sub, '*': operator.mul, '/':
operator.truediv, '%': operator.mod}
def do_math(equation):
if isinstance(equation, list):
op = ops[equation[1]]
return op(do_math(equation[0]), do_math(equation[2]))
else:
return equation
print (do_math([1, '+', [4, '*', [3, '*', 7]], '/', 2]))