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 PawelBubak
from itertools import combinations
def longest_palindromic(text):
list = []
for i in range(len(text),1,-1):
for j in combinations(text,i):
if "".join(j) == "".join(j)[::-1]:
list.append("".join(j))
tab = []
for i in text:
tab.append(i)
palindromic = "".join(tab)
result = []
for i in list:
if i in palindromic:
result.append(i)
helped = []
for i in result:
helped.append(len(i))
if len(helped) == 0:
return text[0]
else:
k = helped.index(max(helped))
return result[k]
Nov. 26, 2016