Python | Reverse each word in a sentence
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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course