6. Find out the number of palindrome strings in a given string - Link
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
Comments
Leave a comment