I have to split a string for example 'star' to a list like ['s','t','a','r'] and have to do it recursively. I know how to do this iteratively but not recursively.
Below is my code to do so but it rightly does not work.
def explode(S):
res = []
res.append(S[0])
if len(S)==1:
return res
else:
res.append(explode(S[1:]))
return res
The output I get is:
['s', ['t', ['a', ['r']]]]
How do I fix this? Is there an example from which I can learn recursion better because this clearly does not work.