This commit is contained in:
adii1823
2021-10-28 17:38:47 +05:30
parent ef37ce0c4e
commit b6eb3ef8a7
32 changed files with 1063 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# oop/class.methods.split.py
class StringUtil:
@classmethod
def is_palindrome(cls, s, case_insensitive=True):
s = cls._strip_string(s)
# For case insensitive comparison, we lower-case s
if case_insensitive:
s = s.lower()
return cls._is_palindrome(s)
@staticmethod
def _strip_string(s):
return ''.join(c for c in s if c.isalnum())
@staticmethod
def _is_palindrome(s):
for c in range(len(s) // 2):
if s[c] != s[-c -1]:
return False
return True
@staticmethod
def get_unique_words(sentence):
return set(sentence.split())
print(StringUtil.is_palindrome('A nut for a jar of tuna')) # True
print(StringUtil.is_palindrome('A nut for a jar of beans')) # False
"""
$ python class.methods.split.py
True
False
"""