We are given a string and we need to reverse words of given string ?
Input : str = "geeks quiz practice code" Output : str = "code practice quiz geeks"
This problem has existing solution please refer Reverse words in a given String link. We will solve this problem in python. Given below are the steps to be followed to solve this problem.
- Separate each word in given string using split() method of string data type in python.
- Reverse the word separated list.
- Print words of list, in string form after joining each word with space using ” “.join() method in python.
"code practice quiz geeks"
This article is contributed by Shashank Mishra (Gullu). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Reverse words in a given string
- Program to reverse words in a given string in C++
- Reverse middle words of a string
- Reverse words in a given String in Java
- Reverse String according to the number of words
- Print words of a string in reverse order
- Python | Words lengths in String
- Python | Extract words from given string
- Iterate over words of a String in Python
- Check if the given string of words can be formed from words present in the dictionary
- Python | Extract odd length words in String
- Python - Words Frequency in String Shorthands
- Python program to print even length words in a string
- Reverse individual words
- Reverse string in Python (5 different ways)
Improved By : TanmayThaakur