title: Place a static variable which returned as a respond within a recursive block
body: <p>I wrote such a recursive solution to merge two sorted list</p>
  
  <pre><code>res = []
  def merge(l1, l2):
      """
      :type l1:List
      :rtype res: List[int]
      """
      #Base
      #Case1: Both are empty Case2 and Case3: One of them is empty
      if len(l1) * len(l2) == 0:
          res = l1 + l2 
          return res
      #Case 4    
      if len(l1) = 1 and len(l2) = 1:
          if l1[0] &lt;= l2[0]:
              res.append(l1.pop(0)) #decrement 
          else:
              res.append(l2.pop(0))
          return res
  
      #Recur Case
      if len(l1) &gt; 1 and len(l2) &gt; 1:
          return merge(l1, l2)
  </code></pre>
  
  <p>The problem I concern is that the static variable <code>res</code> should be defined outside of the function module. In this case,  I might forget to copy <code>res=[]</code> when reuse it in other place. module <code>merge</code> is not independent in a 100% way.</p>
  
  <p>So I place it inside like </p>
  
  <pre><code>def merge(l1, l2):
      """
      :type l1:List
      :rtype res: List[int]
      """
      global res
      try:
          print(res)
      except NameError:
          res = []
  ...
  </code></pre>
  
  <p>The solution is cumbersome,<br>
  How could solve the problem in a succinct way?</p>