I tried to separate a string based on palindrome. But my code splitting extra palindromes in my output what mistake I made?
example: Input 1:
radarnoonlevel
Output 1:
radar noon level
Input 2:
malayalamdadmom
Output 2:
malayalam dad mom
My code:
s="radarnoonlevel"
ans=[]
for i in range(0,len(s)):
for j in range(i+1,len(s)):
if s[i]==s[j] and s[i:j+1]==s[i:j+1][::-1]:
ans+=[s[i:j+1]]
print(*ans)
My output:
radar ada noon oo level eve
I tried to separate a string based on palindrome. But my code splitting strings with extra palindromes in my output what mistake I made?