← Back to challenges

Muddled Middles

PythonHardloopsstrings

Instructions

Given a sentence of all lowercase words, reverse all the letters in each word, but leave the first and last letters as they are.

Examples

mix_middle("the quick brown fox jumps high") ➞ "the qciuk bworn fox jpmus hgih"

mix_middle("this sentence is quite muddled") ➞ "tihs scnetnee is qtiue melddud"

mix_middle("buying a first-class ticket") ➞ "bniyug a fsalc-tsris tekcit"

Notes

  • Treat hyphenated words like one word (example #3).
  • Notice how one, two and three-letter words remain unchanged.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.