Check Palindrome Strings

Write a Python lambda function that checks whether a string is a palindrome or not. A palindrome is a word, phrase, or sequence that reads the same backward as forward. The function should accept a string and return a Boolean.

Example 1:

Input: "radar"
Output: True

Example 2:

Input: "python"
Output: False

A string is a palindrome if it is equal to its reverse. You can use Python’s string slicing technique to get the reverse of a string.

# Define the lambda function
is_palindrome = lambda s: s == s[::-1]

# Test the function
print(is_palindrome("radar"))  # Output: True
print(is_palindrome("python"))  # Output: False

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!