I'm attempting to implement Python's split() function using recursion with no additional parameters and no loops.
For a given input string, this is the desired output
mySplit('hello,there,world', ',')
=> ['hello', 'there', 'world']
Here is my current attempt, but it really only removes the delimiter and places the string in a list, but I cannot figure out how to append items to the list!
def mySplit(string, delim):
if len(string) == 1:
return [string]
if string[0] == delim:
return [mySplit(string[1:], delim)[0]]
return [string[0] + mySplit(string[1:], delim)[0]]
This code results in ['hellothereworld']