Declaring empty variables at the beginning of a recursive function
<p>I've read that you should never test for the existence of a variable; if your program has to check whether a variable exists, you don't "know your variables" and it is a design error. However, I have a recursive function that adds values to a dictionary and a list during each call to the function. In order to avoid declaring global variables, I am trying to make the variables local to the function. But in order to do that, I have to declare myList and myDict as [] and {} in the beginning of the function. Of course, that erases the changes I made to the dict and list in the previous recursive calls, which I don't want. I thought about instating a try ... catch at the beginning, checking for the existence of the variables, and only declaring them as {} and [] if they do not yet exist, but I've read that is bad design. Is there a better way to approach this? I apologize for not attaching any actual code, but I'm still at the beginning stages of planning this function, so there is nothing much to attach. </p>
