def lst_substrings(s,ans):
if len(s) == 0:
print(ans)
ch=s[0]
ros=s[1:]
lst_substrings(ros,ans)
lst_substrings(ros,ans+ch)
s="binod"
ans=" "
lst_substrings(s,ans)
I tried to find list of sub-strings through recursion in python. But I get an error message like this-
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "<string>", line 7, in lst_substrings
File "<string>", line 7, in lst_substrings
File "<string>", line 7, in lst_substrings
[Previous line repeated 2 more times]
File "<string>", line 4, in lst_substrings
IndexError: string index out of range
This same logic fetches result in cpp. I want to go through this approach. Can someone please help me in modifying the code?