You are viewing a single comment's thread. Return to all comments →
Different approach :
import re, sys S = input() k = input() def occurences_indexer(text, target): occurences_indexs = [] initial_text_len = len(text) while True: occurence = re.search(f'{target}', text) if occurence != None: delta_target_len = (initial_text_len-len(text)) occurences_indexs.append((occurence.start()+delta_target_len, occurence.end()+delta_target_len-1)) if re.search(f'{target[0]}', target[1:]) != None: #Searchs for occurence stacking text = re.sub(f'{target}', f'{target[1:]}', text, count=1) else: text = re.sub(f'{target}', '', text, count=1) continue else: break first_search = False if occurences_indexs == []: occurences_indexs.append((-1, -1)) return occurences_indexs for index_tuple in occurences_indexer(S, k): print(index_tuple)
Seems like cookies are disabled on this browser, please enable them to open this website
Re.start() & Re.end()
You are viewing a single comment's thread. Return to all comments →
Different approach :