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.
Asked
Active
Viewed 160 times
-2
-
4... did you try it out??? Why do you think it won't work? – juanpa.arrivillaga Nov 01 '17 at 21:40
1 Answers
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