我试图从本质上获取包含以下句子的字符串列表:
sentence = ['Here is an example of what I am working with', 'But I need to change the format', 'to something more useable']
并将其转换为以下内容:
word_list = ['Here', 'is', 'an', 'example', 'of', 'what', 'I', 'am',
'working', 'with', 'But', 'I', 'need', 'to', 'change', 'the format',
'to', 'something', 'more', 'useable']
我尝试使用这个:
for item in sentence:
for word in item:
word_list.append(word)
我认为它会采用每个字符串并将该字符串的每个项目附加到 word_list,但是输出类似于以下内容:
word_list = ['H', 'e', 'r', 'e', ' ', 'i', 's' .....etc]
我知道我犯了一个愚蠢的错误,但我不知道为什么,有人可以帮忙吗?