I have these two test cases:
calc1 = [['print', 5]] # 5
calc2 = [['print', 2], ['print', 4], ['print', 8]] # 2 4 8
And I can print them correctly with this function:
def exec_program(p):
if len(p) == 1:
print(p[0][1])
else:
for i in p:
print(i[1])
print(exec_program(calc2))
>>> 2
>>> 4
>>> 8
But how can I solve this recursively? The number of items in calc can be 1 or many. All help appreciated
Edit: My current try. Looking for a solution
def exec_program(p):
if len(p) == 1:
print(p[0][1])
else:
print(exec_program[1:] - 1)