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>I believe this solution correctly implements both of the criteria "a list of strings or a list of lists of strings" and "return the same list" without any external assistance:</p>

<pre><code>def noVowels(sequence, index=0):
    if not (sequence and type(sequence) is list and index &lt; len(sequence)):
        return 

    vowels = {'a','i','e','o','u'}

    if type(sequence[index]) is list:
        noVowels(sequence[index])
    elif sequence[index] in vowels:
        del sequence[index]
        index -= 1

    noVowels(sequence, index + 1)

    return sequence
</code></pre>

<p><strong>TEST</strong></p>

<pre><code>array = [['a', 'b', 'c', 'd', 'e'], 'f', 'g', 'h', 'i', ['l', 'm', ['n', 'o', 'p'], 'q'], 'r', 's', 't', 'u']

print(array)
print(id(array))
print(id(array[0]))

result = noVowels(array)

print(result)
print(id(result))
print(id(result[0]))
</code></pre>

<p><strong>RESULT</strong></p>

<pre><code>&gt; python3 test.py
[['a', 'b', 'c', 'd', 'e'], 'f', 'g', 'h', 'i', ['l', 'm', ['n', 'o', 'p'], 'q'], 'r', 's', 't', 'u']
4315447624
4315344520
[['b', 'c', 'd'], 'f', 'g', 'h', ['l', 'm', ['n', 'p'], 'q'], 'r', 's', 't']
4315447624
4315344520
&gt;
</code></pre>

<p>Note that the same list, and inner lists, are left intact based on their id not changing.  And it handles a list of lists of lists.</p>

<p>I don't believe it's functional program because it works by side-effect but that contradiction is inherent in the OP's problem description.</p>

python recursion functional-programming