Words Backward
With strings, you sometimes need to reverse whole words rather than the letters inside them. Given a string s where words are separated by one or more spaces, return the words in reverse order. Use exactly one space between words in the result. Remove any extra spaces from the beginning or end.
Примеры
Ввод
"hello world"Вывод
"world hello"Ввод
" the sky is blue "Вывод
"blue is sky the"Ввод
"single"Вывод
"single"Нужно реализовать
def reverse_words(s):
Теги
stringstwo-pointers
Melde dich an, um den Einreichungsverlauf zu sehen
AnmeldenMelde dich an, um den KI-Mentor zu nutzen
AnmeldenVisible tests
1
Input
"hello world"Expected
"world hello"2
Input
" the sky is blue "Expected
"blue is sky the"3
Input
"single"Expected
"single"4
Input
""Expected
""5
Input
"a b c d"Expected
"d c b a"6
Input
"Hello, World!"Expected
"World! Hello,"Focus radio
Paused · SomaFM · Fluid