You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#KindaHARDChallenge: Write a function that takes a string and returns True if it is a palindrome (reads the same forwards and backwards), and False otherwise.
# How it works:
# 1. Base case: If the string gets reduced to 1 or 0 characters, it means all outer pairs matched, so it returns True.
# 2. Check outer characters: It checks if the first and last characters are different. If they are, it instantly returns False.
# 3. Recursive step: If they match, it recursively checks the remaining substring by slicing off the first and last characters (my_string[1:-1]).
def palindrome_checker(my_string):
# Base case: if the string is empty or a single character, it's a palindrome
if len(my_string) <= 1:
return True
# If the first and last characters don't match, it's not a palindrome
if my_string[0] != my_string[-1]:
return False
# Recursive step: strip the first and last characters and check the remaining inner string