How to find the base case for a recursive function that changes a string of characters in a certain way
<p>Lately I have been working with recursion as, according to my professor, it represents pure functional programming approach as neither changes on variables nor side effects take place. 
Through my previous two questions <a href="http://stackoverflow.com/questions/39704084/how-to-write-a-recursive-function-that-takes-a-list-and-return-the-same-list-wit?noredirect=1#comment66726638_39704084">HERE</a> and <a href="http://stackoverflow.com/questions/39641229/how-to-find-a-given-element-in-nested-lists/39648238?noredirect=1#comment66624227_39648238">HERE</a> I have come to realise that its not the recursive definition per say is my problem, I understand how a recursive definition work and I have tried solving many mathematics related questions using the recursive definition and managed to solve them on first try. Because in mathematics you always have a crystal clear base case such as <code>0!</code> is 1 etc. However when it comes to working with <code>string</code> it seems to be always the case that i have no idea how constitute my base case in form of :</p>

<pre><code>if (something):
     return something
 else:
      invoke the recursive function
</code></pre>

<p>for example give a <code>list</code> of <code>string</code>, or <code>char</code> use a recursive definition to remove the vowels or alphanumeric <code>char</code> etc. As mention earlier its functional programming so no side effects no variable changes are permitted. Which raises the question, such questions are not mathematical how can one come up with base case? </p>

<p>Thanks everybody in advance for helping me to figure out my misery </p>

<p>Well, you're iterating over a list of characters, so your base case can be an empty string. Here's a quick example of a recursive function that removes vowels from a string:</p>

<pre><code>def strip_vowels(str):
    if not str:
        return ''
    if str[0] in ['a', 'e', 'i', 'o', 'u']:
        return strip_vowels(str[1:])
    else:
        return str[0] + strip_vowels(str[1:])
</code></pre>

python recursion functional-programming discrete-mathematics