Editor

Palindrome Check

Strings · Intermediate · 60 XP · about 6 min

Write a function called is_palindrome(s) that returns True if the string is a palindrome (reads the same forwards and backwards), and False otherwise.

The check should be case-insensitive and ignore spaces.

Example

is_palindrome("racecar")      # Returns True
is_palindrome("hello")        # Returns False
is_palindrome("A man a plan a canal Panama")  # Returns True
is_palindrome("Was it a car or a cat I saw")  # Returns True

Requirements

  • Ignore case (treat 'A' and 'a' as the same)
  • Ignore spaces
  • Return a boolean
def is_palindrome(s):
# Your code here
pass
# Test your function
print(is_palindrome("racecar"))
print(is_palindrome("hello"))
print(is_palindrome("A man a plan a canal Panama"))

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.