title: Recursive function in removing occurence in list python
body: <pre><code>def remove_all1(x,s):
      def loop(x,s,ss):
          while s!=[]:
              if x == s[0]:
                  return loop(x,s[2:],ss+[s[1]])
              else:
                  return loop(x,s[1:],ss+[s[0]])
          return ss
      return loop(x,s,[])
  </code></pre>
  
  <p>This is the one I made by recursive tail function to remove recursive value x and if :</p>
  
  <pre><code>print(remove_all1(3,[4,3,5,6,3,2,1]))
  </code></pre>
  
  <p>I would get:</p>
  
  <pre><code>[4,5,6,2,1]
  </code></pre>
  
  <p>The exact result I want. But for the recursive function here:</p>
  
  <pre><code>def remove_all0(x,s):
      while s!=[]:
          if x == s[0]:
              ss = [s[1]] + remove_all0(x,s[2:])
              return ss 
          else:
              s1 = [s[0]] + [remove_all0(x, s[1:])]
              return s1 
      if s==[]:
          return s
  print(remove_all0(3,[4,3,5,6,3,2,1]))
  </code></pre>
  
  <p>I would not get the same result. Instead, I got:</p>
  
  <pre><code>[4, [5, 6, [2, 1, []]]]
  </code></pre>
  
  <p>Why does this happen? </p>