Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
for loop solution in Clear category for Long Repeat Inside by imloafer
def repeat_inside(line: str) -> str:
"""
first the longest repeating substring
"""
# your code here
longest = ''
if len(set(line)) == 1:
return line
for i in range(len(line)//2 +1):
for j in range(len(line)//2 + 2):
if (text := line[i:j] * 2) in line and len(text) > len(longest):
longest = text
return longest
print("Example:")
print(repeat_inside("aabbff"))
assert repeat_inside("aaaaa") == "aaaaa"
assert repeat_inside("abcabcabab") == "abcabc"
assert repeat_inside('') == ''
assert repeat_inside("aabbff") == "aa"
assert repeat_inside("aababcc") == "abab"
assert repeat_inside("abc") == ""
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 7, 2022
Comments: