0
How to find Substring Occurrences in a string in Python. I need to do in hand this is my difficulty, I have to go through the string and if I find two occurrences of substring equal I have to remove one. In the output is counted the number of occurrences of the substrings and return the correct strings.the string are all minuscule and without accent.
string= str(input('digite palavra:'))
for i in range(len(string)):
x=string[-3:]
y=string[-2:]
if string.find(x)and string.find(y):
a = string
b = x or y
for i in range(0,len(b)):
a =a.replace(b[i],"",1)
Print( a)
Example:
Aulaula - retira' ula' fica Aula
Indodo - retira 'do' fica indo
aa- retira o 'a' fica a
Estavatava- retira o 'tava' fica Estava
in my code I can only with the palalvra 'indodo already with the others stays(Auula, aa, Esravatava)
It seems to me you mean seek substrings in words, otherwise you would have to remove the
pr
of programming in practice. And by the look of it also has to be at least two letters otherwise each word could not have repeated letters. Clarify as much as possible the statement, and preferably show what you have done to try to solve it– Isac
Hello Isac, I am in the fight with this code, that’s right I have to look for a substring in each word, can be with 2 or 3 letters or but, in the example Aulaula has two substrings(Ula) with 3 letters, I have to delete the second to be correct.
– Bruno