def get_longest_palindrome(text): best_palindrome = '' length = len(text) for i in range(length * 2 - 1): start = i / 2 - i % 2 end = i / 2 + 1 while start > 0 and end < length and text[start] == text[end]: start -= 1 end += 1 candidate = text[start+1:end] if len(candidate) > len(best_palindrome): best_palindrome = candidate return best_palindrome