title: Using recursion to append to a list python
body: <p>I wrote a recursive program with python2 to obtain the multiplicative persistence of numbers;which is the number of times you must multiply the digits in a number until you reach a single digit. I also want to store all the successive multiplications in the list. </p>
  
  <pre><code>import operator
  def persistence(n, count = []):
      n = list(str(n)) 
      if len(n) == 1:
          return len(count)
      else:
          n = list(map(int, n))
          n = reduce(operator.mul, n)
          count.append(n)
          return persistence(n)
  </code></pre>
  
  <p>The code works for the first function call made, but instead of resetting the count list to an empty list, it retains the values of whatever previously obtained values. </p>
  
  <p>For the first function call:</p>
  
  <pre><code>persistence(39)
  </code></pre>
  
  <p>The output is 3. Which is the expected output. 
  However, when another function call is made:</p>
  
  <pre><code>persistence(4)
  </code></pre>
  
  <p>Instead of getting output 0, it outputs 3; which is the result of the first function call.</p>
  
  <p>I think the problem is the global list. I tried declaring the list inside the function, but it just kept on resetting the list to empty on every recursive call.Can anyone help?</p>