I wrote two simple functions to determine if a string is a palindrome. I thought they were equivalent, but 2 doesn't work. Why is this?
1
def is_palindrome(string):
if string == string[::-1]:
return True
else:
return False
2
def is_palindrome(string):
if string == reversed(string):
return True
else:
return False
See Question&Answers more detail:os