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

标签 python string list

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

 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/

相关文章:

list - DataTable中的Flutter DropdownButton,列表中的DropdownButton选项

Python 摩尔斯电码 : S. O.S

python - 如何在 Python 中使用 WordNet 获取词域?

python - 如何在 python3 中使用列表理解替换值?

c++ - std::string::clear 和 std::list::clear 是否从内存中删除数据

Java : Equals() does not compare right

c - 全局指针(链表头)未正确更新

python - 我可以将步骤定义放在一个不是 "steps"的文件夹中吗?

Python 断言 NDB 项相等

java - Java 中迭代从 'One' String 到 'Another' String 的字符串列表