Python Practice › String Programs › Program 15

Reverse the order of words

EasyString Programs · 15 of 106

Write a Python program to rearrange a sentence so its words appear in reverse order.

Advertisement
Input
"Cricket Plays Virat"
Output
Virat Plays Cricket

Approach

  1. Split, reverse the list, join.

Solution

Python
text = "Cricket Plays Virat"print(" ".join(text.split()[::-1]))
Output
Virat Plays Cricket
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs