Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Longest Palindromic by Krzysztof_Dziedzic
def isPalindromic(txt):
b = len(txt)
for a in range(0, int(b / 2)):
if txt[a] != txt[b - 1]:
return False
b = b - 1
return True
def longest_palindromic(text):
LongestPal = ""
print(text, "\n")
for b in range(0,len(text)):
for a in range(b, len(text) + 1):
Substring = text[b:a]
print(Substring)
if isPalindromic(Substring):
if len(Substring) > len(LongestPal):
LongestPal = Substring
return LongestPal
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Oct. 28, 2016