Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Implement an Instance Method to Update StateE02. Create a Class Method Constructor from a DictionaryE03. Write a Static Method Utility for ValidationE

Problem No 3

Write a Static Method Utility for Validation

Easy

8 minute session

Summary

Implement a static method to check palindromes that ignores case and non-alphanumeric characters.

Problem statement

Create a class StringUtils with a static method is_palindrome(s) that returns True if the string s is a palindrome when non-alphanumeric characters are ignored and case differences are ignored. For example, "A man, a plan, a canal: Panama" should be considered a palindrome. The method should return a boolean value and must be a static method (i.e., decorated with @staticmethod). Do not add any instance or class attributes; the functionality should be provided through a static method because it doesn't rely on instance or class state.

Task

Learn how to declare and use a @staticmethod for a utility that doesn't depend on instance or class state.

Examples

Simple palindrome

Input

StringUtils.is_palindrome('radar')

Output

True

Explanation

The word 'radar' reads the same forwards and backwards.

Input format

A single call to StringUtils.is_palindrome with a string argument.

Output format

Return a boolean: True if the processed string is a palindrome, otherwise False.

Constraints

The method must be defined as a static method (use @staticmethod). The input string may be empty and may contain letters, digits, punctuation and spaces.

Samples

Sample input 0

StringUtils.is_palindrome('A man, a plan, a canal: Panama')

Sample output 0

True

Explanation 0

Ignoring punctuation and case makes this a palindrome.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

03:43 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.