Answer to Question #256251 in Python for rasi

Question #256251

6. Find out the number of palindrome strings in a given string - Link


1
Expert's answer
2021-10-25T04:19:06-0400
def count_palindromes(string):
    count = 0
    string = string.lower()
    for i in range(len(string) - 1):
        for j in range(i + 2, len(string) + 1):
            substr = string[i:j]
            if substr[:len(substr) // 2] == substr[-1:-(len(substr) // 2) - 1:-1]:
                count += 1
    return count

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS