Skip to content

Commit 01b7148

Browse files
authored
Add files via upload
1 parent a000cfd commit 01b7148

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

string-processing/palindrome.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
find if given sentence or word is palindrome.
3+
Sentence/word may have non alphanumeric characters too.
4+
"""
5+
6+
def palindrome_check(sentence):
7+
i = 0
8+
j = len(sentence)-1
9+
while i < j :
10+
if not sentence[i].isalnum() and i<j:
11+
i+=1
12+
if not sentence[j].isalnum() and i<j:
13+
j-=1
14+
15+
if sentence[i].lower() != sentence[j].lower():
16+
return False
17+
18+
19+
i+=1
20+
j-=1
21+
return True
22+
23+
print(palindrome_check("Live on time, emit no evil."))

0 commit comments

Comments
 (0)