我想将我的字符串拆分成单独的句子。 我的代码在下面
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/