Receiving TypeError: can only concatenate list (not "NoneType") to list
<p>For my computer science class, we are learning recursion and I'm having difficulty understanding it. One part of my assignment is to create an algorithm that returns another list that is identical to L except all elements of e are removed. However, I am currently coming up with a   </p>

<blockquote>
  <p>TypeError: can only concatenate list (not "NoneType") to list</p>
</blockquote>

<p>What does this mean and how can I fix it</p>

<pre><code>def removeAll(e, L):
    '''returns another list that is identical to L except all elements of e are removed'''
     if L==[]:
         return []
     if L[0]!=e:
         return [L[0]]+removeAll(e,L[1:])
</code></pre>

<p><a href="http://i.stack.imgur.com/bWVeG.png" rel="nofollow">Code</a></p>

<p>You are checking for <code>L</code> being an empty list, and you are checking whether the first element of <code>L</code> is not equal to <code>e</code> (and thus part of your result), but as soon as an element is equal to <code>e</code>, your function returns nothing, meaning that it returns a default value of <code>None</code>. Add the proper handling for that situation with an <code>else</code>:</p>

<pre><code>else:
    return removeAll(e, L[1:])
</code></pre>

python functional-programming