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
PostgreSQLv16

Qui apparirà il risultato dell'esecuzione del codice

Visible tests
1
Input
"Hello how are you Contestant", 4
Expected"Hello how are you"
2
Input
"What is the solution to this problem", 4
Expected"What is the solution"
3
Input
"chopper is not a tanuki", 5
Expected"chopper is not a tanuki"
4
Input
"a", 1
Expected"a"
5
Input
"one two three", 1
Expected"one"
6
Input
"Hello how are you ContestantHello how are you Contestant", 8
Expected"Hello how are you ContestantHello how are you"
Focus radio
Paused · SomaFM · Fluid