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

Function is_palindrome

strings/palindrome.py:21–37  ·  view source on GitHub ↗

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

(s: str)

Source from the content-addressed store, hash-verified

19
20
21def is_palindrome(s: str) -> bool:
22 """
23 Return True if s is a palindrome otherwise return False.
24
25 >>> all(is_palindrome(key) == value for key, value in test_data.items())
26 True
27 """
28
29 start_i = 0
30 end_i = len(s) - 1
31 while start_i < end_i:
32 if s[start_i] == s[end_i]:
33 start_i += 1
34 end_i -= 1
35 else:
36 return False
37 return True
38
39
40def is_palindrome_traversal(s: str) -> bool:

Callers 1

palindrome.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected