All problems
Reverse Words in a String
Problem
Reverse the order of words in text and return the result with single spaces between words, with no leading or trailing spaces.
Split on arbitrary whitespace and rejoin the reversed list with single spaces. An input of only spaces yields the empty string.
Hint
Python split without arguments handles all whitespace and removes empty strings.
Test cases
case 1
in: ["the sky is blue"]
expected: "blue is sky the"
case 2
in: [" hello world "]
expected: "world hello"
case 3
in: ["a good example"]
expected: "example good a"
case 4
in: [""]
expected: ""
case 5
in: [" "]
expected: ""
Starter codePython
def reverse_words(text):
# Your code here
pass5 test cases · run your code against them in the editor