title: Flatten vs SumList Function
body: <p>I wrote a flatten function that turns a nested list into one list</p>
  
  <pre><code>def flatten(lst, new=[]):
      for i in lst:
          if type(i)==list:
              flatten(i)
          else:
              new+=[i]
      return new
  </code></pre>
  
  <p>I tried using the same logic to make a function that adds up all positive numbers found in the nested list. </p>
  
  <pre><code>def posSum(lst, Sum=0):
      for i in lst:
          if type(i)==list:
              posSum(i)
          else:
              if i &gt; 0:
                  Sum+=i
      return Sum
  </code></pre>
  
  <p>This returns 0. Why is it the "new" variable gets updated in flatten, but Sum doesn't get updated in posSum? I even put a print statement in my else clause to see if I could print out all the "i"s, which works. I tried putting a return for posSum instead of just calling it, but then it only calculates the sum for the first element since it breaks the loop. How can I get around this in one function, as opposed to me flattening the list, and then going through the new list?</p>