Kth word X69738


Statement
 

pdf   zip

html

Write a function kth_word(s, k) that given a string s and an integer k≥ 1 returns the kth word in string s. If s has less than k words it returns the empty string. We assume all characters of s are letters and spaces. Warning: do not use the split string method.

Sample session
>>> kth_word('Alea iacta est', 3)
'est'
>>> kth_word('Alea iacta est', 1)
'Alea'
>>> kth_word('KingKong', 2)
''
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python