-
Code def is_palindrome(s: str) -> bool: s = ''.join(i for i in s.lower() if i.isalnum()) return s == s[::-1]
Test Cases import codewars_test as test # TODO Write tests test.assert_equals(is_palindrome("Taco Cat"), True) test.assert_equals(is_palindrome("Are we not pure? No, sir! Panama's moody Noriega brags. It is garbage! Irony dooms a man - a prisoner up to new era."), True) test.assert_equals(is_palindrome("Sit on a potato pan Milo"), False) test.assert_equals(is_palindrome("A man, a plan, a canal - Panama."), True) test.assert_equals(is_palindrome("oh no bees!"), False) import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) .describe("Example") def test_group(): .it("test case") def _(): test.assert_equals(is_palindrome("A man, a plan, panama"), False) test.assert_equals(is_palindrome("Bob Racecar"), False) test.assert_equals(is_palindrome("Are we not drawn onward to new era?"), True)
Output:
-
Code import string- def is_palindrome(s: str) -> bool:
forward = s.lower().translate(str.maketrans('', '', string.punctuation + ' '))return forward == forward[::-1]- s = ''.join(i for i in s.lower() if i.isalnum())
- return s == s[::-1]
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}