Created
October 3, 2011 15:53
-
-
Save alexalemi/1259430 to your computer and use it in GitHub Desktop.
Longest Palindrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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