我有一个具有以下结构的列表:
input =
[['Business']
['Technology']
['Technology Business Sports']]
我想将句子拆分为单词并创建以下结构:
result =
[['Business']
['Technology']
['Technology', 'Business', 'Sports']]
我试过了
result = input
for i, s in enumerate(input):
result[i] = s[0].split()
print(result)
但是我得到了错误:
ValueError:无法将大小为2的序列复制到数组轴
维度1
最佳答案
您想要这样的东西:
>>> data = [['Business'],
... ['Technology'],
... ['Technology Business Sports']]
>>>
>>> [inner[0].split() for inner in data]
[['Business'], ['Technology'], ['Technology', 'Business', 'Sports']]