First Words Only
When creating a short preview, you often keep only the first few words of a sentence. Given a string s, where words are separated by single spaces, and a number k, return a sentence made from only the first k words.
Примеры
Ввод
"Hello how are you Contestant", 4Вывод
"Hello how are you"Ввод
"What is the solution to this problem", 4Вывод
"What is the solution"Ввод
"chopper is not a tanuki", 5Вывод
"chopper is not a tanuki"Нужно реализовать
def truncate_sentence(s: str, k: int) -> str:
Теги
strings
Connectez-vous pour voir l'historique des soumissions
Se connecterConnectez-vous pour utiliser le Mentor IA
Se connecterVisible tests
1
Input
"Hello how are you Contestant", 4Expected
"Hello how are you"2
Input
"What is the solution to this problem", 4Expected
"What is the solution"3
Input
"chopper is not a tanuki", 5Expected
"chopper is not a tanuki"4
Input
"a", 1Expected
"a"5
Input
"one two three", 1Expected
"one"6
Input
"Hello how are you ContestantHello how are you Contestant", 8Expected
"Hello how are you ContestantHello how are you"Focus radio
Paused · SomaFM · Fluid