In this post, we are going to create a simple python function program which will take in a string and then reverses all those words within that string.

We are going to accomplish our goal in three steps. 1) Spit the string into a list of words 2) Reverse the list 3) Return the new reversed string.

def reverseWords(str):
    reverse = str.split(' ')
    reverse.reverse()
    return ' '.join(reverse)

Very simple solution, if you got better idea, leave your thought under the comment box below!

Please follow and like us:
error0

Leave a Reply

Your email address will not be published. Required fields are marked *