I have to use a recursive function in python, code below is a simplified model.
I want to preserve result list and dict dictionary not generate a new list or dictionary while in the recursive, and return it after recursive, how to solve it?
def test(length):
result = []
dict = {}
if length == 10:
return result, dict
else:
result.append(length)
dict[length] = length + 1
test(length + 1)
x, y = test(0)
print x, y
Use a helper function that performs the recursion, and the main function to call the helper with the initial defaults.