Print last character of each word in a string | Function to print the last character of each word in the given string ; Now , last word is also followed by a space ; If current character is a space ; Then previous character must be the last character of some word ; Driver code
def printLastChar ( string ) : NEW_LINE INDENT string = string + " ▁ " NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT if string [ i ] == ' ▁ ' : NEW_LINE INDENT print ( string [ i - 1 ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT string = " Geeks ▁ for ▁ Geeks " NEW_LINE printLastChar ( string ) NEW_LINE