Split Text into Words
When you want to process text word by word, the first step is often turning it into a list. Write string_to_array, which takes a string s and returns a list of words separated by spaces. If the string is empty, return a list containing one empty string.
Примеры
Ввод
"Robin Singh"Вывод
["Robin", "Singh"]Ввод
"I love arrays"Вывод
["I", "love", "arrays"]Ввод
""Вывод
[""]Нужно реализовать
def string_to_array(s: str) -> list[str]:
Теги
stringslistsarray
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
IdħolVisible tests
1
Input
"Robin Singh"Expected
["Robin","Singh"]2
Input
"I love arrays"Expected
["I","love","arrays"]3
Input
""Expected
[""]4
Input
"one"Expected
["one"]5
Input
"a b c"Expected
["a","b","c"]6
Input
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Expected
["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]Focus radio
Paused · SomaFM · Fluid