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 Stanislaw_Szataniak
def is_p(a):
if a == a[::-1]:
return True
def longest_palindromic(text):
p=[]
max1=0
for i in range(len(text)):
for j in range(i+1,len(text)+1):
if is_p(text[i:j]):
p.append(text[i:j])
if len(text[i:j]) > max1:
max1 = len(text[i:j])
for i in p:
if len(i) == max1:
return i
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Nov. 18, 2016