Reversing each word
Write code · Basic · §3.3 Working with strings
Complete the function solution, which returns sentence with the characters of each word in reverse order.
Keep the words in their original order. Words are separated by a single space.
Function
solution(sentence)
Constraints
- The length of
sentenceis from 1 to 1,000. sentenceconsists of English letters, digits, and spaces. It does not start or end with a space, and there are never two or more spaces in a row.
Examples
| sentence | result |
|---|---|
'hello world' | 'olleh dlrow' |
'python practice' | 'nohtyp ecitcarp' |
Starter code
def solution(sentence):
answer = ""
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.