Last active
June 25, 2020 02:17
-
-
Save jasonappah/c85af8b84f513d1bb272092c04111c56 to your computer and use it in GitHub Desktop.
Palindrome?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a quick script I wrote to find if a string is a palindrome. | |
# I feel like there's probably a more efficient way of doing this, but it works. To my credit, I did this in about 45 minutes. | |
x = "20200202" | |
def isPalindrome(str=""): | |
if str=="": | |
return -1 | |
elif str[::1] == str: | |
return True | |
else: | |
return False | |
print (isPalindrome(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reverse, you can just use [::-1]. I think it's written in C rather than Python, so it should run way faster.