So I'm trying to figure out this question, it asks me to split a string and returns a tuple of the split strings, this is supposed to be done with recursion, with absolutely no usage of loops. This is the function that I've managed to come up with:
def split_path(s):
tup=[]
i=s.find("/")
if i!=-1:
tup.append(s[0:i])
new_str=s[i+1:]
tup.append(split_path(new_str))
else:
tup.append(s)
return tup
"E:/cp104/2005/labs/lab11t4" is the string I'm putting into the function, the output SHOULD be:
['E:', 'cp104','2005','labs','lab11t4']
but this is what I have:
['E:', ['cp104', ['2005', ['labs', ['lab11t4']]]]]
So right now I'm successfully getting all of the values in the string that I need, I know the problem is that I'm returning a tuple so it's just appending a tuple within a tuple so my outer tuple only has 2 elements in it.
So how exactly do I untuple the inner elements so I can make the final tuple 1 dimensional instead of the 5 dimensional one that I have?