The challenge

Write a function that checks if a given string (case insensitive) is a palindrome.

The solution in Python

Option 1:

1
2
3
4
5
6
7
def is_palindrome(s):
    s = s.lower()
    for i, item in enumerate(s):
        if i<len(s)/2:
            if s[i]!=s[len(s)-i-1]:
                return False
    return True

Option 2:

1
2
3
def is_palindrome(s):
    s = s.lower()
    return s == s[::-1]

Option 3:

1
2
def is_palindrome(s):
    return s.lower()==s[::-1].lower()

Test cases to validate our solution

1
2
3
4
5
6
7
8
9
@test.describe('sample tests')
def sample_tests():
    test.assert_equals(is_palindrome('a'), True)
    test.assert_equals(is_palindrome('aba'), True)
    test.assert_equals(is_palindrome('Abba'), True)
    test.assert_equals(is_palindrome('malam'), True)
    test.assert_equals(is_palindrome('walter'), False)
    test.assert_equals(is_palindrome('kodok'), True)
    test.assert_equals(is_palindrome('Kasue'), False)