I am trying to find the indices of a repetitive word in a string without whitespaces.
let's say the string is:
x = "catdogmousecathorsecatdog"
I am trying to find the index of where the word 'cat'
is
so the output should be 0, 11, 19
I am trying to find the indices of a repetitive word in a string without whitespaces.
let's say the string is:
x = "catdogmousecathorsecatdog"
I am trying to find the index of where the word 'cat'
is
so the output should be 0, 11, 19
try this,
>>> string = "catdogmousecathorsecatdog"
>>> [i for i in range(len(string)) if string.startswith('cat', i)]
[0, 11, 19]