2017-03-15 62 views
0

我有句子的列出清单的单词的一个列表蟒蛇

['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) 
+2

你有没有试过*任何*? – timgeb

+1

你可以附加列表 – Harsha

回答

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) 
+1

我有一个循环产生这些列表,大约150个列表... for newList: t = s [1] .lower().split('') print(t) –

+0

然后你想要什么输出.. –

+0

@keithchingotah我已更新多个列表,你可以检查并告诉我任何代码的问题。 –

1

+是列表,连接符

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

biglist = list1 + list2 + list3 
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.'] 
+0

这个错误,它去了嵌套列表,OP不想嵌套列表。 – Hackaholic

+0

是的..它是扩展..我已经更新了我的答案 – Harsha

+0

我有一个循环正在产生这些列表,以及如果有500.如何添加所有500个? –