Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # Проверить, является ли строка палиндромом.
  2. # isPalindrome("Do geese see God?") -> true;
  3.  
  4. def isPalindrome(str):
  5.     first = 0
  6.     last = len(str) - 1
  7.     if len(str) <= 1:
  8.         return True
  9.     while True:
  10.         while str[first].isalpha() == False:
  11.             first += 1
  12.         while str[last].isalpha() == False:
  13.             last -= 1
  14.         if first >= last:
  15.             return True
  16.         if str[first].lower() == str[last].lower():
  17.             first += 1
  18.             last -= 1
  19.             if first - last == 1:
  20.                 return True
  21.         else:
  22.             return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement