We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Re.start() & Re.end()
Re.start() & Re.end()
Sort by
recency
|
315 Discussions
|
Please Login in order to post a comment
Not the ideal solution, because it's prone to exeptions. However, it provides sufficient answear and it's simple enought given the provided example code.
text = input("Enter text: ") k = input("Enter k: ") k_len = len(k) r = 0 count = 0
while r + k_len <= len(text): if text[r:r + k_len] == k: print(f'({r}, {r + k_len - 1})') count += 1
if count == 0: print(f'(-1, -1)')