Words Backward
Sometimes you need to reverse the order of words, not the letters inside them, like rearranging tags or parts of a phrase. The function reverse_words receives a string s and returns a new string where the words appear in reverse order. Words in the input string are separated by single spaces.
Примеры
Ввод
"hello world"Вывод
"world hello"Ввод
"a b c"Вывод
"c b a"Ввод
"single"Вывод
"single"Нужно реализовать
def reverse_words(s: str) -> str:
Теги
strings
Connectez-vous pour voir l'historique des soumissions
Se connecterConnectez-vous pour utiliser le Mentor IA
Se connecterVisible tests
1
Input
"hello world"Expected
"world hello"2
Input
"a b c"Expected
"c b a"3
Input
"single"Expected
"single"4
Input
""Expected
""5
Input
"one two three"Expected
"three two one"6
Input
"a b ca b c"Expected
"c b ca b a"Focus radio
Paused · SomaFM · Fluid