InferenceAI

Enter at least two characters to search.

Start free

Reverse Word Order

easyArrays & Strings15 min10 XP

Return the words of s in reverse order, separated by single spaces, with no leading or trailing spaces.

Examples

EXAMPLE WALKTHROUGHbasic

A guided view of the published example, not a trace of your code.

INPUT["the sky is blue"]
TASKreverse_word_order()
EXPECTED OUTPUT"blue is sky the"

Start with the input values shown in this example.

Example 1 of 3

Input: s = "the sky is blue"

Output: "blue is sky the"

Explanation: basic

Input: s = " hello world "

Output: "world hello"

Explanation: extra spaces

Input: s = "a good example"

Output: "example good a"

Explanation: repeated spaces

Hint 1

split() with no argument discards extra whitespace.

Topics

DSAArrays & StringsPython