【发布时间】:2022-01-21 17:11:45
【问题描述】:
我试图提取每 5 个单词的第一个字母,经过一些研究,我能够弄清楚如何获取每 5 个单词。但是,我怎么知道提取每 5 个单词的第一个字母并将它们放在一起以构成一个单词。这是我到目前为止的进展:
def extract(text):
for word in text.split()[::5]:
print(word)
extract("I like to jump on trees when I am bored")
【问题讨论】:
-
你可以只取字符串的第 0 个元素,比如 word[0]
-
顺便说一句,对于你所坚持的任务,已经有几十个类似的问题了。谷歌
python split extract first letter of every word in string.
标签: python function split extract