Rebuild the Sentence

Imagine a sentence where the words were shuffled, but each word still has a number showing its real position. Write a function sort_sentence that receives a string where every word ends with a number from 1 to 9. Sort the words by those numbers, remove the numbers, and return the original sentence.

Примеры

Ввод
"is2 sentence4 This1 a3"
Вывод
"This is a sentence"
Ввод
"Myself2 Me1 I4 and3"
Вывод
"Me Myself and I"
Ввод
"word1"
Вывод
"word"

Нужно реализовать

def sort_sentence(s: str) -> str:

Теги

stringssortingarray
PostgreSQLv16

Tu sa zobrazí výsledok spustenia kódu

Visible tests
1
Input
"is2 sentence4 This1 a3"
Expected"This is a sentence"
2
Input
"Myself2 Me1 I4 and3"
Expected"Me Myself and I"
3
Input
"word1"
Expected"word"
4
Input
"a1 b2 c3"
Expected"a b c"
5
Input
"second2 first1"
Expected"first second"
6
Input
"x3 y1 z2"
Expected"y z x"
Focus radio
Paused · SomaFM · Fluid