human
Modify a sentence by reversing order of occurrences of all Palindrome Words | Function to check if a string S is a palindrome.
Function to print the modified string after reversing teh order of occurrences of all palindromic words in the sentence.
Stores the palindromic words.
Stores the words in the list.
Traversing the list.
If current word is a palindrome.
Update newlist.
Reverse the newlist.
Traverse the list.
If current word is a palindrome.
Update lis [ i ].
Increment j.
Print the updated sentence.
Driver Code"
Solution in Python:
assistant
#Here is code to modify a sentence by reversing order of occurrences of all Palindrome Words and the other steps required.
 def palindrome ( string ) :
	if ( string == string [ : : - 1 ] ) :
		return True
	else :
		return False
def printReverse ( sentence ) :
	newlist = [ ]
	lis = list ( sentence . split ( ) )
	for i in lis :
		if ( palindrome ( i ) ) :
			newlist . append ( i )
	newlist . reverse ( )
	j = 0
	for i in range ( len ( lis ) ) :
		if ( palindrome ( lis [ i ] ) ) :
			lis [ i ] = newlist [ j ]
			j = j + 1
	for i in lis :
		print ( i , end = " ▁ " )
sentence = " mom ▁ and ▁ dad ▁ went ▁ to ▁ eye ▁ hospital "
printReverse ( sentence )