Given a long sentence, reverse each word of the sentence individually in the sentence itself.
Input : Geeks For Geeks is good to learn Output : skeeG roF skeeG si doog ot nrael Input : Split Reverse Join Output : tilpS esreveR nioJ
We shall use Python’s built in library function to reverse each word individually in the string itself.
- First split the sentence into list of words.
- Reverse each word of the string in the list individually.
- Join the words in the list to form a new sentence.
Below is the implementation of above idea.
skeeGrofskeeG si doog ot nrael
Python is well known for its short codes. We shall do the same task but with lesser line of codes.
skeeG rof skeeG
- Program to replace a word with asterisks in a sentence
- Python program to read file word by word
- Python | Spilt a sentence into list of words
- Python | Check if given words appear together in a list of sentence
- Python | Remove all duplicates words from a given sentence
- Python program to count words in a sentence
- Python | Sort words of sentence in ascending order
- Python - Get Nth word in given String
- Python | Word Stretch
- Python - Kth word replace in String
- Generating Word Cloud in Python
- Python | Word Similarity using spaCy
- Python | Word Embedding using Word2Vec
- Second most repeated word in a sequence in Python
- Generating Word Cloud in Python | Set 2
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.