我试图基本上采用包含句子的字符串列表,例如:
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,但输出的内容如下:
06003
我知道我犯了一个愚蠢的错误,但我无法弄清楚为什么,任何人都可以帮忙吗?