In this segment, you will learn about a useful functionality of strings and lists called reverse().
Let’s take an example to illustrate it. You will be given a sentence in the form of a string. You have to reverse the order of the words in the sentence. Remember not to reverse the individual words, character by character, but the order of words. Before we see Sajan explain how we can do this with a very small code, can you try it out?
Did you get the desired output? Did you use a for loop? Let's see how Sajan approaches this problem.
Let's see how do we implement the above pseudocode in Python.
Note that Sajan uses split(' '), whereas using only split() would have worked too as default argument for split function is space. It is always a good practice to not depend on default arguments and pass them the same like space in split function.