Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def first(word):
- """Returns the first character of a string."""
- return word[0]
- def last(word):
- """Returns all but the first character of a string."""
- return word[-1]
- def middle(word):
- """Returns all but the first and last characters of a string."""
- return word[1:-1]
- def is_palindrome(word):
- """Returns True if word is a palindrome."""
- if len(word) <= 1:
- return True
- if first(word) != last(word):
- return False
- return is_palindrome(middle(word))
- def main(text):
- longest = ""
- highscore = 0
- list1 = []
- a = len(text)
- for b in range(a):
- for c in range(a-1):
- word = str(text[c:c+b])
- d = is_palindrome(word)
- if d == True:
- list1.append(word)
- if len(word) > highscore:
- longest = word
- highscore = len(word)
- return longest
- if __name__ == "__main__":
- text = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth"
- longest = main(text)
- print "The First Password is:",longest
Advertisement
Add Comment
Please, Sign In to add comment