write a function that tests whether a string is a palindrome

Solutions on MaxInterview for write a function that tests whether a string is a palindrome by the best coders in the world

showing results for - "write a function that tests whether a string is a palindrome"
Geena
13 Nov 2020
1def palindrome_check(string):
2    string = list(string)
3    tmp = []
4    #remove any spaces
5    for x in range(0, len(string)):
6        if(string[x] != " "):
7            tmp.append(string[x].lower())
8    
9            
10    #now reverse the string
11    array1 = []
12    i = 0
13    j = len(tmp)-1
14
15    while(i < len(tmp)):
16        array1.append(tmp[j])
17        i += 1
18        j -= 1
19
20    #check if array1 is equal to the string
21    counter = 0
22    for x in range(0, len(tmp)):
23        if(tmp[x] == array1[x]):
24            counter += 1
25
26    #if the counter is equal to the length of the string then the word
27    #is the same
28    if(counter == len(tmp)):
29        return True
30    
31    return False
similar questions