Reverse words in string Python
PROGRAM TO REVERSE THE STRING BY CONSIDERING EACH WORD OF THE STRING
OUTPUT
code practice quiz
# Function to reverse the words # of a given strring def printRev(strr): # Stack to store each # word of the strring strr = strr.split(" ") st = [] # Store the whole strring # in strream for i in strr: # Push each word of the # into the stack st.append(i) # Print the in reverse # order of the words while len(st) > 0: print(st[-1], end = " ") del st[-1] # Driver Code if __name__ == '__main__': strr = "geeks quiz practice code" printRev(strr)
code practice quiz
Comments
Post a Comment