Write a program in python to count all palindrome words present in a sentence or string.

Example:

For this, we need to loop through each word in the sentence and compare each word with its corresponding reverse. If they are equal then we will increment the count.

In python a word can be easily reversed by word[::-1]

Instead of counting, we will store all the palindrome words in a list, so that it can be printed or used for other purposes.

Output

If you have any suggestions or doubts then comment below.

Leave a Reply

Close Menu