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 CyprianSzlachciak
# migrated from python 2.7
from itertools import combinations
def czy_pal(a):
return a == a[::-1]
def longest_palindromic(text):
najd = ""
for s, e in combinations(list(range(len(text) + 1)), 2):
print(("s= ",s))
print(("e= ",e))
wycinek = text[s:e]
if czy_pal(wycinek) and len(najd) < len(wycinek):
najd = wycinek
return najd
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. 24, 2016