-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.py
More file actions
36 lines (31 loc) · 816 Bytes
/
palindrome.py
File metadata and controls
36 lines (31 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 14 16:18:54 2017
@author: thelma
"""
def isPalindrome(s):
"""
s: str
output: True if s is a Palindrome, otherwise False.
"""
def toChars(s):
"""
turn s into all lower characters and remove any non characters
"""
s = s.lower()
ans = ""
for c in s:
if c in "abcdefghijklmnopqrstuvwxyz":
ans = ans + c
return ans
def isPal(s):
"""
check to see if s is a palindrome by moving from outside to inside
5"""
if len(s) <= 1:
return True
else:
return s[0] == s[-1] and isPal(s[1:-1])
return isPal(toChars(s))
print(isPalindrome("Madam, I am Adam"))