7 examples of 'palindrome program in python without using string functions' in Python

Every line of 'palindrome program in python without using string functions' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
21def isPalindrome(string):
22 leftIdx = 0
23 rightIdx = len(string) - 1
24 while leftIdx < rightIdx:
25 if string[leftIdx] != string[rightIdx]:
26 return False
27 leftIdx += 1
28 rightIdx -= 1
29 return True
13def isPalindromeIterative(string):
14 start = 0
15 end = len(string) - 1
16 while start < end:
17 start = start + 1
18 end = end - 1
19 if string[start] != string[end]:
20 return False
21 return True
35def isPalindrome(self, A):
36 low, high = 0, len(A) - 1
37 while low < high:
38
39 while low < high and not A[low].isalnum():
40 low += 1
41
42 while low < high and not A[high].isalnum():
43 high -= 1
44
45 if A[low].lower() != A[high].lower():
46 return 0
47
48 low, high = low + 1, high - 1
49
50 return 1
174def test_is_palindrome(self):
175 # 'Otto' is a old german name.
176 self.assertTrue(is_palindrome("Otto"))
177 self.assertFalse(is_palindrome("house"))
14def isPalindrome(self, s):
15 """
16 :type s: str
17 :rtype: bool
18 """
19 cleaned = re.sub('[^0-9a-zA-Z]', '', s)
20 if cleaned.lower() == cleaned[::-1].lower():
21 return True
22 return False
31@staticmethod
32def is_palindrome(num):
33 return str(num) == ''.join(reversed(str(num)))
34def isPalindrome(self, s: 'str') -> 'bool':
35 s = ''.join(filter(str.isalnum, s)).lower()
36 return s == s[::-1]

Related snippets