Kth word X69738


Statement
 

pdf   zip

Write a function @kth_word(s, k)@ that given a string ss and an integer k1k\ge 1 returns the $k{\it th}$ word in string ss. If ss has less than kk words it returns the empty string. We assume all characters of ss are letters and spaces. Warning: do not use the split string method.

Sample session

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