Python Practice › String Programs › Program 15
Reverse the order of words
Write a Python program to rearrange a sentence so its words appear in reverse order.
Input
"Cricket Plays Virat"
Output
Virat Plays Cricket
Approach
- Split, reverse the list, join.
Solution
text = "Cricket Plays Virat"print(" ".join(text.split()[::-1]))Output
Virat Plays Cricket
Learn the concept
New to this topic? Read the lesson, then come back.