Open the context
Choose the project folder and name the files or behavior involved.
Return the leftmost longest palindromic substring of at most 512 code points. Test empty text, even centers and equal-length ties, comparing code points without Unicode normalization or grapheme segmentation.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def longest_palindrome(text):
if type(text) is not str or len(text) > 512:
raise ValueError("palindrome.input")
best = (0, 0)
for center in range(len(text)):
for left, right in ((center, center), (center, center+1)):
while left >= 0 and right < len(text) and text[left] == text[right]:
stop = right+1
if stop-left > best[1]-best[0] or (stop-left == best[1]-best[0] and left < best[0]):
best = (left, stop)
left -= 1
right += 1
return text[best[0]:best[1]]
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.