How to write a recursive function that takes a list and return the same list without vowels?
<p>I am supposed to write a recursive function that takes a list of strings or a list of lists of strings and return the list without vowels, if found. Here is my attempt to solve it:</p>

<pre><code>def noVow(seq):
    keys = ['a','i','e','o','u','u']
    if not seq or not isinstance(seq, list) :
        return 
    else:
        if seq[0]  in keys:
            del seq[0]
            return (noVow(seq[0:]))
        else:
            return (noVow(seq[1:]))


li = ["b", "c", "d","a"]
print (noVow(li))
</code></pre>

<p>I am aware that the bug lies in my base case however I can't come up with the right base case. </p>

<p>Note that the recursive function has to be written in pure functional programming i.e. side effects are not allowed.</p>

<p>Your base case returns a None. So whenever you passes the empty list the None is sent up the stack of recursive calls. </p>

<p>Moreover you are not storing the characters which are not vowels, so your else case is wrong.</p>

<p>What you can have is something like this: </p>

<pre><code>&gt;&gt;&gt; def noVow(seq):
...     keys = ['a','i','e','o','u','u']
...     if not seq or not isinstance(seq, list) :
...         return []
...     else:
...         if seq[0] in keys:
...             return noVow(seq[1:])
...         else:
...             return [seq[0]] + noVow(seq[1:])
</code></pre>

<p>Also <code>seq[0:]</code> is equivalent to <code>seq</code>.</p>

python recursion functional-programming