Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_palindrome(sentence):
- fwd = 0
- bak = len(sentence) - 1
- while fwd < bak:
- a = sentence[fwd]
- if not a.isalpha() and not a.isdigit():
- fwd += 1
- continue
- b = sentence[bak]
- if not b.isalpha() and not b.isdigit():
- bak -= 1
- continue
- if a.lower() != b.lower():
- print(sentence, "is not palindromic")
- break
- fwd += 1
- bak -= 1
- else: # the loop did NOT end with break
- print(sentence, "is palindromic")
- # output: [email protected] is palindromic
- # output: [email protected] is palindromic
Add Comment
Please, Sign In to add comment