Sorting the Sentence
|
|
In this code:
- We split the input string
s
into words and store them instrings
. - For each
string
instrings
, we extract the last character, which is the index. We convert it to an integer and use it as an index to place thestring
(without the last character) into the correct position in therearranged
list. - We join the words in the
rearranged
list into a string, with spaces between each word. This is stored in theresult
list. - Finally, we join the
result
list into a string and return it.