Reverse each word in a linked list node | Node of a linked list ; Function to create newNode in a linked list ; reverse each node data ; iterate each node and call reverse_word for each node data ; printing linked list ; Driver program
class Node : NEW_LINE INDENT def __init__ ( self , next = None , data = None ) : NEW_LINE INDENT self . next = next NEW_LINE self . data = data NEW_LINE DEDENT DEDENT def newNode ( c ) : NEW_LINE INDENT temp = Node ( ) NEW_LINE temp . c = c NEW_LINE temp . next = None NEW_LINE return temp NEW_LINE DEDENT def reverse_word ( str ) : NEW_LINE INDENT s = " " NEW_LINE i = 0 NEW_LINE while ( i < len ( str ) ) : NEW_LINE INDENT s = str [ i ] + s NEW_LINE i = i + 1 NEW_LINE DEDENT return s NEW_LINE DEDENT def reverse ( head ) : NEW_LINE INDENT ptr = head NEW_LINE while ( ptr != None ) : NEW_LINE INDENT ptr . c = reverse_word ( ptr . c ) NEW_LINE ptr = ptr . next NEW_LINE DEDENT return head NEW_LINE DEDENT def printList ( head ) : NEW_LINE INDENT while ( head != None ) : NEW_LINE INDENT print ( head . c , end = " ▁ " ) NEW_LINE head = head . next NEW_LINE DEDENT DEDENT head = newNode ( " Geeksforgeeks " ) NEW_LINE head . next = newNode ( " a " ) NEW_LINE head . next . next = newNode ( " computer " ) NEW_LINE head . next . next . next = newNode ( " science " ) NEW_LINE head . next . next . next . next = newNode ( " portal " ) NEW_LINE head . next . next . next . next . next = newNode ( " for " ) NEW_LINE head . next . next . next . next . next . next = newNode ( " geeks " ) NEW_LINE print ( " List ▁ before ▁ reverse : ▁ " ) NEW_LINE printList ( head ) NEW_LINE head = reverse ( head ) NEW_LINE print (   " List after reverse :   " ) NEW_LINE printList ( head ) NEW_LINE