MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_palindrome_recursive

Function is_palindrome_recursive

strings/palindrome.py:59–71  ·  view source on GitHub ↗

Return True if s is a palindrome otherwise return False. >>> all(is_palindrome_recursive(key) == value for key, value in test_data.items()) True

(s: str)

Source from the content-addressed store, hash-verified

57
58
59def is_palindrome_recursive(s: str) -> bool:
60 """
61 Return True if s is a palindrome otherwise return False.
62
63 >>> all(is_palindrome_recursive(key) == value for key, value in test_data.items())
64 True
65 """
66 if len(s) <= 1:
67 return True
68 if s[0] == s[len(s) - 1]:
69 return is_palindrome_recursive(s[1:-1])
70 else:
71 return False
72
73
74def is_palindrome_slice(s: str) -> bool:

Callers 1

palindrome.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected