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()
+ 0 comments import re s, p = input(), re.compile(input()) start, end = -1,-1 while 1: result = p.search(s,start+1) if result: start = result.start() end = result.end()-1 print((start,end)) else: if start < 0: print((start,end)) break
+ 0 comments Enter your code here. Read input from STDIN. Print output to STDOUT
import re
string = input() substring = input()
pattern = re.compile(substring) match = pattern.search(string) if not match: print('(-1, -1)') while match: print('({0}, {1})'.format(match.start(), match.end() - 1)) match = pattern.search(string, match.start() + 1)
+ 0 comments import re s = input() k = input() pattern = re.compile(k) match = pattern.search(s) if match == None: print((-1, -1)) else: for i in range(0, len(s)): a = pattern.match(s, pos=i, endpos=i+len(k)) if a: print((a.span()[0], a.span()[-1]-1))
+ 0 comments import re S=input() k=input() reg_ex=f'{k[0]}(?={k[1:]})' m_n=re.findall(reg_ex,S) m = re.finditer(reg_ex,S) if len(m_n): for i in m: start=i.start() end=start+len(k)-1 tupla=(start,end) print(tupla) else: print((-1,-1))
+ 0 comments import re s = input() d = input() m = re.search(d, s) output = [] while m: start_index = m.start() end_index = m.end() output.append("("+str(start_index)+", "+str(end_index-1)+")") s = s.replace(s[start_index], "0", 1) m = re.search(d, s) if output: output = list(set(output)) output.sort() for i in output: print(i) else: print("(-1, -1)")
Load more conversations
Sort 302 Discussions, By:
Please Login in order to post a comment