Computer Science, asked by malininkl99, 16 days ago

Remove the words that are palindrome in a given sentence
Ex:
Input: "He did a good deed"
output: "He good"
input: "Malayalam is my mother tongue"
output: " is my mother tongue"

Answers

Answered by tarunverma731
2

Answer:

def remove_palindrome(sntc):

 word_list = sntc.split()     #splitting the sentence in list of words

 result = ""

 for word in word_list:    #traversing in word list

   if word.lower() != word.lower()[::-1]:      #checking each word for palindrome

     result = result + word + " "           #adding each non palindrome to result

 return result

print(remove_palindrome("He did a good deed"))

print(remove_palindrome("Malayalam is my mother tongue"))

Explanation:

Similar questions