Python 拆分字符串数组

标签 python

我有一个 Python 列表,如下所示:

["Hello, My Name is John", "Good Afternoon, my name is David", "I am three years old"]

我想将每个字符串拆分成逗号分隔的列表并存储结果,并将每个单词转换为小写:

[['hello','my','name','is','john'], ['good','afternoon','my','name','is','david'],['i','am','three','years','old']]

关于如何做到这一点有什么建议吗? 谢谢。

最佳答案

您可以简单地将逗号替换为空格并去除字符串的其余部分。

strList = ["Hello, My Name is John", "Good Afternoon, my name is David", "I am three years old"]
[i.lower().replace(',', '').split() for i in strList]

关于Python 拆分字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54976948/

相关文章:

python - 三次Hermite样条插值python

python - 使用 BeautifulSoup 提取跨度类文本时没有返回

python - linux写的编译shell文件是什么

python - 将重复元素设置为零

python - 如何多次从带有关键字开始和结束的列表中获取子列表

python - 两个Python对象如何具有相同的id但“is”运算符返回False?

Python - 服务器从两个 UDP 套接字监听

python - tensorflow map_fn 是否支持采用多个张量?

python - 使用 Robot Framework 中的内置函数的自定义关键字中出现预期错误

python - Tensorflow 1.8 GPU版本似乎在windows上不使用GPU