的名單我有這樣轉換列表的列表,以字符串
list1 = [['I am a student'], ['I come from China'], ['I study computer science']]
len(list1) = 3
列表的列表現在我想將其轉換成字符串列表這樣
list2 = ['I', 'am', 'a', 'student','I', 'come', 'from', 'China', 'I','study','computer','science']
len(list2) = 12
我我知道,我可以轉換這樣
new_list = [','.join(x) for x in list1]
但它返回
['I,am,a,student','I,come,from,China','I,study,computer,science']
len(new_list) = 3
我也試過這個
new_list = [''.join(x for x in list1)]
,但它提供了以下錯誤
TypeError: sequence item 0: expected str instance, list found
我如何在列表1的子表中提取每一個字,並把它轉換成字符串列表?我使用python 3在Windows 7
列表1有一個元素是有三個元素的列表。 – bohrax
如果列表1有你的問題可能應該改寫,以「轉換句子的列表單詞列表」三個要素 – bohrax
@bohrax,對不起,我已編輯的問題,它應該是列表的列表。 –