Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def IsAlmostPalindrome(word):
- """
- Check if the word is or almost is a palindrome.
- To be almost a palindrome, we would need to change
- only one character.
- Parameters
- ----------
- word: str
- The word to be checked
- Returns
- -------
- True if the word is a palindrome or almost. False
- otherwise
- """
- count = 0
- for i in range(len(word)//2):
- if word[i] != word[-i-1]:
- count+=1
- if count >1:
- return False
- return True
- assert IsAlmostPalindrome('abccba')
- assert IsAlmostPalindrome('abccbg')
- assert not IsAlmostPalindrome('abccfg')
Add Comment
Please, Sign In to add comment