Suppose we have a string of words delimited by spaces; we have to reverse the order of words.
So, if the input is like "Hello world, I love python programming", then the output will be "programming python love I world, Hello"
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, s): temp = s.split(' ') temp = list(reversed(temp)) return ' '.join(temp) ob = Solution() sentence = "Hello world, I love python programming" print(ob.solve(sentence))
"Hello world, I love python programming"
programming python love I world, Hello