← Back to challenges

Reverse the Odd Length Words

PythonHardstringsloopsformatting

Instructions

Given a string, reverse all the words which have odd length. The even length words are not changed.

Examples

reverse_odd("Bananas") ➞ "sananaB"

reverse_odd("One two three four") ➞ "enO owt eerht four"

reverse_odd("Make sure uoy only esrever sdrow of ddo length")
➞ "Make sure you only reverse words of odd length"

Notes

There is exactly one space between each word and no punctuation is used.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Number of Leap Years