Problem Statement:

Create a function with the name check_palindrome which takes a list of strings as input. The function checks each string of the list whether it is a palindrome or not and returns another list containing the palindrome from the input string.Note:

i. A palindrome is a a word, phrase, or sequence that reads the same backwards as forwards, e.g. madam
ii. The check for the string to be palindrome should be case-insensitive , e.g. madam and Madam both should be considered as palindrome.

You can use the below sample input and output to verify your solution.

Sample Input:
3
Hello
Malayalam
Radar

Output:

Malayalam
Radar

The first line in the sample input is the count of strings to be included in the list as the 1st input.
The strings are then provided one by one as the next lines of input.
For more details, please refer to the below main section of code
You can use the below sample main section to test your code.

Sample Main Method:

if __name__=='__main__': count=int(input()) inp_str=[] for i in range(count): inp_str.append(input()) output=check_palindrome(inp_str) if len(output)!=0: for i in output: print(i) else: print('No palindrome found')

Solution:

                  #Define the check_palindrome function here 
def check_palindrome(int_str):
	result=[]
	for i in int_str:
		j=i.lower()
		if j==j[::-1]:
			result.append(i)
	return result
     
  

#Sample main section.  

#Do not remove the below portion of code.  

if __name__=='__main__': 

        count=int(input()) 

        inp_str=[] 

        for i in range(count): 

                inp_str.append(input()) 

        output=check_palindrome(inp_str) 

        if len(output)!=0: 

                for i in output: 

                        print(i) 

        else: 

                print('No palindrome found')
            

Sample Input:
3
Hello
Malayalam
Radar

Output:

Malayalam
Radar

Any queries leave a comment please and thanks for reading this post.

4 comments

    1. Don’t copy paste the code drictly in your IDLE, only follow the steps and we will work on it enable good code editor on our website, thanks for visiting our website.

Leave a Reply

Your email address will not be published. Required fields are marked *