Reverse String according to the number of words | Reverse the letters of the word ; Temporary variable to store character ; Swapping the first and last character ; This function forms the required string ; Checking the number of words present in string to reverse ; Reverse the letter of the words ; Driver Code
def reverse ( string , start , end ) : NEW_LINE INDENT temp = ' ' NEW_LINE while start <= end : NEW_LINE INDENT temp = string [ start ] NEW_LINE string [ start ] = string [ end ] NEW_LINE string [ end ] = temp NEW_LINE start += 1 NEW_LINE end -= 1 NEW_LINE DEDENT DEDENT def reverseletter ( string , start , end ) : NEW_LINE INDENT wstart , wend = start , start NEW_LINE while wend < end : NEW_LINE INDENT if string [ wend ] == " ▁ " : NEW_LINE INDENT wend += 1 NEW_LINE continue NEW_LINE DEDENT while wend <= end and string [ wend ] != " ▁ " : NEW_LINE INDENT wend += 1 NEW_LINE DEDENT wend -= 1 NEW_LINE reverse ( string , wstart , wend ) NEW_LINE wend += 1 NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " Ashish ▁ Yadav ▁ Abhishek ▁ Rajput ▁ Sunil ▁ Pundir " NEW_LINE string = list ( string ) NEW_LINE reverseletter ( string , 0 , len ( string ) - 1 ) NEW_LINE print ( ' ' . join ( string ) ) NEW_LINE DEDENT