Clean Spaces
Users often type text with extra spaces at the beginning, at the end, or between words. Write a function trim_spaces that cleans up the string s: remove spaces around the edges and replace multiple inner spaces with a single space. If the string contains only spaces, return an empty string.
Примеры
Ввод
" hello world "Вывод
"hello world"Ввод
"a b c"Вывод
"a b c"Ввод
" "Вывод
""Нужно реализовать
def trim_spaces(s: str) -> str:
Теги
strings
Zaloguj się, aby zobaczyć historię rozwiązań
Zaloguj sięZaloguj się, aby korzystać z Mentora AI
Zaloguj sięTests12
Visible tests
Ukryty test 7
Ukryty test 8
Ukryty test 9
Ukryty test 10
Ukryty test 11
Ukryty test 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid