Lately I tried to figure out a question implementing split() function, objective is to complete a function that split a string with delimiters such as "-" or a path string with "/"s to a list of words in a recursive manner.
inputString = "Hello-World"
expectedOutput = ["Hello", "World"]
Tried the solution using find(), is there any other possible solution without using linear functions?
def splitString(str, delim):
list=[]
i=str.find(delim)
if i!=-1:
list.append(str[0:i])
newStr=str[i+1:]
list.extend(splitString(newStr, delim))
else:
list.append(str)
return list
strorlistas the name for a variable or function argument. Those are already the name of python's builtin classlistand python's builtin classstr. If you shadow these names by reusing them for a particular variables, everything becomes confusing.