Skip to content

Instantly share code, notes, and snippets.

@alexalemi
Created October 3, 2011 15:53
Show Gist options
  • Save alexalemi/1259430 to your computer and use it in GitHub Desktop.
Save alexalemi/1259430 to your computer and use it in GitHub Desktop.
Longest Palindrome
import difflib
def longest_palindrome(text):
matcher = difflib.SequenceMatcher(None,text,text[::-1])
length = len(text)
a,b,k = matcher.find_longest_match(0,length-1,0,length-1)
return text[a:a+k]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment