Creating 2 strings out of 1 recursively
<p>I'm trying to write a program that takes a string(stringg) apart and creates 1 string with all uppercase letters in stringg and 1 string with all lowercase letters in stringg. </p>

<p>result should be something like this:</p>

<pre><code>split_rec('HsaIm') = ('HI', 'sam')
</code></pre>

<p>This is how I have tried to write it recursively.</p>

<pre><code>def split_rec(stringg):

    if not stringg: 
        return ('')
    elif stringg[0].isupper() == True and stringg[0].isalpha() == True:
        return stringg[0] + split_rec(stringg[1:]), split_rec(stringg[1:])
    elif stringg[0].isupper() == False and stringg[0].isalpha() == True:
        return split_rec(stringg[1:]), stringg[0] + split_rec(stringg[1:])
</code></pre>

<p>But when I try it I get the error code "Can't convert 'tuple' object to str implicitly". Any kind of help is appreciated.</p>

<p>First avoid test like so:</p>

<pre><code>if condition == True:
</code></pre>

<p>and write simply</p>

<pre><code>if condition:
</code></pre>

<p>Then you need to return a tuple and access the result as a tuple in all cases:</p>

<pre><code>def split_rec(stringg):

    if not stringg: 
        return ('','')
    else:
        first = stringg[0]
        assert first.isalpha(), "The string contains invalid characters."
        upper, lower = split_rec(stringg[1:])
        if first.isupper():
            return first + upper, lower
        else:
            return upper, first + lower
</code></pre>

python string tuples