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 Lachesis_132296
def palindromic(s):
for i in range(0, len(s)//2):
if s[i] != s[len(s)-i-1]:
return False
return True
def longest_palindromic(text):
maks = text[0]
cur = text[0]
for i in range(0, len(text)-1):
for j in range(i+1, len(text)):
cur = text[i:j+1]
if palindromic(cur) and len(cur) > len(maks):
maks = cur
return maks
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Dec. 1, 2016