Day 7Reverse the Words

    Easystringslists

    Write reverse_words(sentence) that returns the words of sentence in reverse order, separated by single spaces.

    reverse_words("I love Python") returns "Python love I".

    Examples

    Example 1
    >>> reverse_words("I love Python")
    "Python love I"
    Example 2
    >>> reverse_words("  hello   world ")
    "world hello"

    Good to know

    • Ignore extra spaces: the result has exactly one space between words and none at the ends.

    Run examples checks the 2 examples above. Submit runs all 5 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write reverse_words in the editor, then run the examples. Use print() freely: its output is shown for each test.