gpt4 book ai didi

python - 用逗号分割字符串,这样每个句子都是一个单独的字符串

转载 作者:行者123 更新时间:2023-12-05 08:21:33 31 4
gpt4 key购买 nike

我想将我的字符串拆分成单独的句子。我的代码在下面

 import tensorflow as tf
import pandas as pd

text = 'My cat is a great cat, this is very nice, you are doing great job'

text = text.split(',')

输出:

 ['My cat is a great cat', ' this is very nice', ' you are doing great job']

但我希望这个输出是

 ['My cat is a great cat'] ['this is very nice'] ['you are doing great job']

这可能吗??

最佳答案

是的,这是可能的,我们上面已经给出了答案,但是要匹配上面提到的确切预期输出,请使用以下内容:

inputlist = "apple,banana,cherry"
print(*[[s] for s in inputlist.split(',')],end=" ")

输出:

['apple'] ['banana'] ['cherry'] 

关于python - 用逗号分割字符串,这样每个句子都是一个单独的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72902348/

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