gpt4 book ai didi

python - 按第二个空格拆分字符串

转载 作者:太空宇宙 更新时间:2023-11-03 12:13:27 25 4
gpt4 key购买 nike

输入:

"The boy is running on the train"

预期输出:

["The boy", "boy is", "is running", "running on", "on the", "the train"]

在 python 中实现这个最简单的解决方案是什么。

最佳答案

line="The boy is running on the train"
words=line.split()
k=[words[index]+' '+words[index+1] for index in xrange(len(words)-1)]
print k

输出

['The boy', 'boy is', 'is running', 'running on', 'on the', 'the train']

关于python - 按第二个空格拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18546338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com