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 Machinero
def longest_palindromic(text):
l = text.lower()
r = []
for i in range(len(text)):
for j in range(0, i):
text_portion = text[j:i+1]
if text_portion == text_portion[::-1]:
r.append(text_portion)
if len(r) > 0:
return max(r, key = len)
else:
return text[0]
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. 3, 2016