-2

If I reverse a string using [::-1] can I then just compare it to the original to test if it is a palindrome? My other plan is to create a list or set with the alphabet in it and index the letters of the string to compare numerically if the simple way doesn't work out.

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172

1 Answers1

1

Yes. You can.

def is_palindrome(a_string):
    if a_string == a_string[::-1]:
        return True
    return False

Or simpler:

def is_a_palindrome(a_string):
    return a_string == a_string[::-1]
jgritty
  • 11,660
  • 3
  • 38
  • 60