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 Haradd
def longest_palindromic(text):
pali=""
pali_len=0
pom=""
for i in range(len(text)+1):
for j in range(1,len(text)+1):
pom=text[i:j]
if pom==pom[::-1] and len(pom)>pali_len:
pali=pom
pali_len=len(pom)
return pali
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. 31, 2016