Task
You are given a string S.
Your task is to find the indices of the start and end of string k in S.
solution that someone came to
You are given a string S.
Your task is to find the indices of the start and end of string k in S.
solution that someone came to
S = input() k = input() import re pattern = re.compile(k) r = pattern.search(S) if not r: print(-1,-1) while r: print('({0},{1})'.format(r.start(), r.end()-1)) r = pattern.search(S, r.start()+1)I could use some help in uderstanding it - how while loop works here is not clear to me. I understand that .start() and .end() give indices of k in S. Is this correct? Secondly, why decrease of r.end() by one? And what this line
r = pattern.search(S, r.start()+1)means? Does it start search for k in S from second indice?