How to get all palindrome substrings in a string with Python

1 Answer

0 votes
def is_palindrome(s, i, j) :
  rev = s[i: j]
  rev = rev[::-1]
  tmp_s = s[i: j]
  b = False
  if tmp_s == rev and len(tmp_s) >= 2:
      b = True
  return b;


s = "abaab";
         
for i in range(len(s)): 
  for j in range(i + 1, len(s) + 1): 
      if is_palindrome(s, i, j):
         print(s[i: j])


'''
run:

aba
baab
aa

'''

 



answered Oct 23, 2019 by avibootz

Related questions

1 answer 165 views
1 answer 156 views
1 answer 235 views
1 answer 180 views
1 answer 171 views
1 answer 186 views
1 answer 181 views
...