Generate a python script to check if the string is a palindrome, you are the enterprise…
- User
Generate a python script to check if the string is a palindrome, you are the enterprise software engineer, so add documentation, and tests too
Assistant
Here's a Python script to check if a string is a palindrome. I've added documentation (docstrings) and tests using the
unittestmodule.# is_palindrome.py def is_palindrome(s: str) -> bool: """Check if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization. Args: s (str): The input string. Returns: bool: True if the input string is a palindrome, False otherwise. """ s = ''.join(c.lower() for c in s if c.isalnum()) return s == s[::-1] import unittest class TestIsPalindrome(unittest.TestCase): def test_is_palindrome(self): self.assertTrue(is_palindrome('racecar')) self.assertTrue(is_palindrome('A man a plan a canal Panama')) self.assertTrue(is_palindrome('noon')) self.assertFalse(is_palindrome('hello')) self.assertFalse(is_palindrome('world')) self.assertFalse(is_palindrome('Python')) if __name__ == '__main__': unittest.main(argv=['first-arg-is-ignored'], exit=False)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.