Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Check Palindrome with Loop

Determine whether a string is a palindrome using explicit loops and ignoring non-alphanumeric characters.

Python practice18 minLoops & IterationIntermediateLast updated March 15, 2026

Problem statement

Write is_palindrome(s) that returns True if the string s is a palindrome when considering only alphanumeric characters and ignoring case, otherwise return False. Use loops (for or while) to compare characters; do not use slicing like s[::-1] or the reversed() built-in for the main comparison logic. Examples of treatment: - 'A man, a plan, a canal: Panama' -> True - 'race a car' -> False - Empty string or strings with no alphanumeric characters are palindromes (return True).

Task

Implement a function that checks if a string reads the same forwards and backwards, ignoring case and non-alphanumeric characters, using loops (no slicing for reversal).

Examples

Classic palindrome phrase

Input

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

Output

True

Ignoring non-alphanumeric characters and case, the string becomes 'amanaplanacanalpanama', which is the same forwards and backwards.

Input format

A single argument: s (string).

Output format

Boolean True if palindrome according to the rules, otherwise False.

Constraints

String length <= 1000. Use explicit loops for comparison; you may use str.isalnum() and str.lower().

Samples

Sample 1

Input

is_palindrome('Racecar')

Output

True

Case-insensitive palindrome.