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