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
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
means? Does it start search for k in S from second indice?
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
1 2 3 4 5 6 7 8 9 10 11 |
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 ) |
1 |
r = pattern.search(S, r.start() + 1 ) |