Python – Reverse a words in a line and keep the special characters untouched
Reverse the characters in all words in a line including numbers, but leave special characters and symbols untouched in the same position. Consider the below examples.
Input: ‘Bangalore is@#$!123 locked again in jul2020’ should change to
Output: ‘erolagnaB si@#$!321 dekcol niaga ni 0202luj’
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
Input: ‘Bangalore is@#$!123locked locked again in jul2020’ should change to
Output: ‘erolagnaB si@#$!dekcol321 dekcol niaga ni 0202luj’
Look at the above example, each word is reversed, if there is any special character, then the word surrounding the special character gets reversed.
erolagnaB si@#$!dekcol321 dekcol niaga ni 0202luj