Created
July 10, 2013 20:36
-
-
Save eigenn/5970091 to your computer and use it in GitHub Desktop.
Python finding palindromes
This file contains 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
""" | |
Python palidrome finders. | |
3 methods for finding palindromes with python. | |
""" | |
def is_palindrome_v1(s): | |
if len(s) <= 1: | |
return True | |
else: | |
return s[0] == s[-1] and is_palindrome_v1(s[1:-1]) | |
is_palindrome_v2 = lambda s: s == s[::-1] | |
def is_palindrome_v3(s): | |
return s == ''.join(reversed(s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment