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>

<pre><code>split_rec = lambda x: tuple(map(''.join, zip(*[(a,'') if a.isupper() else ('',a) for a in x if a.isalpha()])))

&gt;&gt;&gt; split_rec('HsaIm')
('HI', 'sam')
</code></pre>

<p>This takes your string and sorts each letter as upper or lower case by putting it on the right or left side of a tuple. Then it unzips the tuples (using <code>zip(*[...])</code>), applies a <code>join</code> function to each to make them back into strings and then makes the whole thing a tuple again.</p>

<p>Just in case you needed a one-line solution </p>

python string tuples