Weekly Coding Challenge: Break camelCase with recursion – written in python

Posted by

Hello readers! It’s really important for me to continue my practice and learning. Every week, I block off 30 minutes, set a timer and choose a challenge from codewars. This helps me keep my skills sharp, see how other devs all over the planet would solve these problems, and take some leisure time to problem solve and be creative. Being able to see other solutions expands my mind for solving future problems in a clever and efficient way. Today, the problem set focuses on Python.

Complete the solution so that the function will break up camel casing, using a space between words.


"camelCasing"  =>  "camel Casing"
"identifier"   =>  "identifier"
""             =>  ""


def solution(s):
    # join the result of recurStrEval
    return ' '.join(recurStrEval(s, '', []))
def recurStrEval(str, temp_str, str_arr):
    # if str is blank, append whats left and return
    if not str:
        return str_arr
    # if first letter of str is upper, append the temp str to array and then restart cycle
    if str[0].isupper():
        temp_str = str[0]
        return recurStrEval(str[1:], temp_str, str_arr)
    # if str is lower, concatenate to the existing string
    if str[0].islower():
        temp_str += str[0]
        return recurStrEval(str[1:], temp_str, str_arr)

All solutions are also now on my GitHub profile if you want to check out all of the coding challenges I’ve completed so far!

All credit to problem sets goes to codewars

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s