列表列表单个单词列表python

时间:2017-03-15 10:34:42

标签: python list

我的句子是

['big', 'mistake.']
['our', 'room', 'was', 'tiny,']
['and', 'the', 'bath', 'was', 'small', 'too.']

如何在python中创建一个列表中包含所有单词的列表。

到此

['big', 'mistake.','our', 'room', 'was', 'tiny,','and', 'the', 'bath',...]

 t = s[1].lower().split(' ')    
 print(t)

3 个答案:

答案 0 :(得分:1)

+是列表连接运算符

list1 = ['big', 'mistake.']
list2 = ['our', 'room', 'was', 'tiny,']
list3 = ['and', 'the', 'bath', 'was', 'small', 'too.']

biglist = list1 + list2 + list3

答案 1 :(得分:0)

a=['big', 'mistake.']
b=['our', 'room', 'was', 'tiny,']
c=['and', 'the', 'bath', 'was', 'small', 'too.']

d=a+b+c
print(d)

您可以+将一个列表附加到另一个列表中......

<强>输出

['big', 'mistake.','our', 'room', 'was', 'tiny,''and', 'the', 'bath', 'was', 'small', 'too.']

多列表

 for s in newList: 
    t = t + s
 print(t)

答案 2 :(得分:0)

您可以添加列表,也可以使用extend关键字

>>> l1 = ['big', 'mistake.']
>>> l2 = ['our', 'room', 'was', 'tiny,']
>>> l3 = ['and', 'the', 'bath', 'was', 'small', 'too.']
>>> l1+l2+l3
['big', 'mistake.', 'our', 'room', 'was', 'tiny,', 'and', 'the', 'bath', 'was', 'small', 'too.']

>>> l1 = ['big', 'mistake.']
>>> l2 = ['our', 'room', 'was', 'tiny,']
>>> l3 = ['and', 'the', 'bath', 'was', 'small', 'too.']
>>> l1.extend(l2)
>>> l1.extend(l3)
>>> print l1
['big', 'mistake.', 'our', 'room', 'was', 'tiny,', 'and', 'the', 'bath', 'was', 'small', 'too.']
相关问题