Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re. + for... solution in Speedy category for Long Repeat Inside by Serg900vd
import re
def repeat_inside(line):
"""
first the longest repeating substring
"""
result, pat_0, pat_1 = '', r'(', r')(\1)+'
for j in line:
pat_0 += '.'
match = re.search(pat_0 + pat_1, line)
if match:
result = max(result, line[match.start():match.end()], key=len)
return result
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert repeat_inside('aaaaa') == 'aaaaa', "First"
assert repeat_inside('aabbff') == 'aa', "Second"
assert repeat_inside('aababcc') == 'abab', "Third"
assert repeat_inside('abc') == '', "Forth"
assert repeat_inside('abcabcabab') == 'abcabc', "Fifth"
print('"Run" is good. How is "Check"?')
April 20, 2022
Comments: