我有一个 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/