You are on the right track. The main problem is that ""
is an empty line, not a space (and even if you fix it, you probably won't want a space after the last word).
Here's how you can do it more briefly:
>>> s='The dog ran' >>> ' '.join(w[::-1] for w in s.split()) 'ehT god nar'
source share