1. def get_longest_palindrome(text):
  2. best_palindrome = ''
  3. length = len(text)
  4. for i in range(length * 2 - 1):
  5. start = i / 2 - i % 2
  6. end = i / 2 + 1
  7. while start > 0 and end < length and text[start] == text[end]:
  8. start -= 1
  9. end += 1
  10. candidate = text[start+1:end]
  11. if len(candidate) > len(best_palindrome):
  12. best_palindrome = candidate
  13. return best_palindrome