Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,987 questions

51,931 answers

573 users

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 141 views
1 answer 139 views
1 answer 177 views
1 answer 154 views
1 answer 143 views
1 answer 161 views
1 answer 157 views
...