From 3812f505216dc2313a0a5545c46fe7a06a030fa9 Mon Sep 17 00:00:00 2001 From: joemarini Date: Fri, 26 May 2023 16:32:32 -0700 Subject: [PATCH] Update the palindrome challenge --- Ch2 - Basics/challenge_solution.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Ch2 - Basics/challenge_solution.py b/Ch2 - Basics/challenge_solution.py index e34cdcf..caeb9dc 100644 --- a/Ch2 - Basics/challenge_solution.py +++ b/Ch2 - Basics/challenge_solution.py @@ -3,7 +3,18 @@ # def is_palindrome(teststr): - # use the slice trick to reverse the string + # one way to do it: calculate the reverse of the string + # reversestr = "" + # strindx = len(teststr)-1 + # while (strindx >= 0): + # reversestr += teststr[strindx] + # strindx -= 1 + + # if teststr == reversestr: + # return True + # return False + + # more advanced: use the slice trick to reverse the string if teststr == teststr[::-1]: return True return False