I have a string abccddde
I need to find substrings like: a, b, c, cc, d, dd, ddd, e
substrings ab or cd are not valid.
I tried finding all the substrings from a string but its not efficient
def get_all_substrings(input_string):
length = len(input_string)
return [input_string[i:j+1] for i in range(length) for j in range(i,length)]
This is outputting:
['a', 'ab', 'abc', 'abcc', 'abccd', 'abccdd', 'abccddd', 'abccddde', 'b', 'bc', 'bcc', 'bccd', 'bccdd', 'bccddd', 'bccddde', 'c', 'cc', 'ccd', 'ccdd', 'ccddd', 'ccddde', 'c', 'cd', 'cdd', 'cddd', 'cddde', 'd', 'dd', 'ddd', 'ddde', 'd', 'dd', 'dde', 'd', 'de', 'e']
This was the method i followed to find the substrings but it gives all the possiblities but that is what makes it inefficient Please Help!