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 Molot
from itertools import combinations
def longest_palindromic(text):
r = [text[i[0]:i[1]] for i in combinations(range(len(text)+1), 2) if text[i[0]:i[1]]==text[i[0]:i[1]][::-1]]
return sorted(r, key=lambda x: len(x), reverse=True)[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"
June 12, 2018
Comments: