{"id":17348,"date":"2021-08-17T20:23:07","date_gmt":"2021-08-17T14:53:07","guid":{"rendered":"https:\/\/python-programs.com\/?p=17348"},"modified":"2021-11-22T18:37:21","modified_gmt":"2021-11-22T13:07:21","slug":"__trashed","status":"publish","type":"post","link":"https:\/\/python-programs.com\/__trashed\/","title":{"rendered":"Python Program to Sort Palindrome Words in a Sentence"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find the Sum of Digits of a Number at Even and Odd places<\/a>
\nGiven a string and the task is to sort all the palindrome words in a given sentence.<\/p>\n

Palindrome:<\/strong><\/p>\n

If the reverse of the given string is the same as the given original string, it is said to be a palindrome.<\/p>\n

Example :<\/p>\n

Given string = “sos asked to bring the madam pip “.<\/p>\n

Output :<\/p>\n

Explanation: In this “madam”, “pip”, “sos” are the palindromic words. By sorting them we get {“madam”, ‘pip’ , “sos”}<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given string\/sentence ='sos how are you madam pip instal'<\/pre>\n

Output:<\/strong><\/p>\n

The given string before sorting all the palindromic words is =  sos how are you madam pip instal\r\nThe final string after sorting all the palindromic words is =  madam how are you pip sos instal<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given string\/sentence = 'the good is madam aba dad mom din cac'<\/pre>\n

Output:<\/strong><\/p>\n

The given string before sorting all the palindromic words is = the good is madam aba dad mom din cac\r\nThe final string after sorting all the palindromic words is = the good is aba cac dad madam din mom<\/pre>\n

Program to Sort Palindrome Words in a Sentence in Python<\/h2>\n

Below are the ways to sort all the palindromic words in a given sentence:<\/p>\n