Drill

ProblemsPython › warmup

Reverse the order of the words

easywarmupPython

A text filter turns a sentence back to front, word by word, without disturbing the words themselves.

reverse_words(text: string) → string

Solve it in the editor →

Where you start

def reverse_words(text: str) -> str:
    

Worked examples

CallResult
reverse_words("the quick brown fox")"fox brown quick the"
reverse_words(" a b ")"b a"
reverse_words("one")"one"
reverse_words("")""

Hint

Split on whitespace, reverse the list, join with a single space.

Reference solution in Python
def reverse_words(text: str) -> str:
    return ' '.join(reversed(text.split()))

The same problem in another language

More warmup problems in Python