From 10f96df197cd63ceccbfbef06c8763f131157b4e Mon Sep 17 00:00:00 2001 From: Julian Santos Date: Thu, 23 Jul 2020 19:47:47 -0500 Subject: [PATCH] Implemented is_palindrome function --- src/main.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 86f3f66..a7735ef 100644 --- a/src/main.py +++ b/src/main.py @@ -15,8 +15,27 @@ def is_palindrome(palindrome): # Start coding here - pass + # I will develop this function with loops, it's too easy to do it with slices + #String preparation: to lowercase and delete the spaces + palindrome = palindrome.lower() + palindrome = palindrome.replace(' ', '') + + #loop through each character of the string, comparing the first with the last, and so on. + str_len = len(palindrome) + + i = 0 + j = str_len - 1 + + while i < str_len: + if palindrome[i] != palindrome[j]: + return False + i += 1 + j -= 1 + + return True + + def validate(): for palindrome in PALINDROMES: if not is_palindrome(palindrome):