Skip to content

Instantly share code, notes, and snippets.

@jasonappah
Last active June 25, 2020 02:17
Show Gist options
  • Save jasonappah/c85af8b84f513d1bb272092c04111c56 to your computer and use it in GitHub Desktop.
Save jasonappah/c85af8b84f513d1bb272092c04111c56 to your computer and use it in GitHub Desktop.
Palindrome?
# 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))
@agarmu
Copy link

agarmu commented Jun 5, 2020

For reverse, you can just use [::-1]. I think it's written in C rather than Python, so it should run way faster.

@jasonappah
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment