From 0a9135b5b3bad1ab30a1ef19d19a60645d6b3186 Mon Sep 17 00:00:00 2001 From: Atin Bainada <61903527+atin@users.noreply.github.com> Date: Tue, 13 Apr 2021 21:31:28 +0530 Subject: [PATCH] Added doctest in palindrome.py (#172) * Added doctest in palindrome.py * small change to re run lint_python test --- strings/python/palindrome.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/strings/python/palindrome.py b/strings/python/palindrome.py index f8be67a9..6c5a9664 100644 --- a/strings/python/palindrome.py +++ b/strings/python/palindrome.py @@ -1,10 +1,22 @@ #!/usr/bin/python3 -# Palindrome Check Function on Python 3 +# Palindrome Check Function using Python 3 # The Palindrome Algorithm # this takes in a string and returns a boolean equal to the result of -# whether the program is a palindrome or not. +# whether the string is a palindrome or not. +string_1 = "abba" +string_2 = "abbcccbba" +string_3 = "abbccbbba" + def palindrome(s: str) -> bool: + """ + >>> palindrome(string_1) + True + >>> palindrome(string_2) + True + >>> palindrome(string_3) + False + """ # Reverse string using idiomatic python reversed_string = s[::-1] # return the answer, by comparing string and its reverse @@ -22,9 +34,6 @@ def is_palindrome(s: str): # main program if __name__ == "__main__": - string_1 = "abba" - string_2 = "abbcccbba" - string_3 = "abbccbbba" is_palindrome(string_1) is_palindrome(string_2) is_palindrome(string_3)