在Python中合并子列表

24 浏览
0 Comments

在Python中合并子列表

这个问题已经有答案了

如何将列表中的列表平铺成一维列表?

如何在Python中连接两个列表?

如何将[[\'a\',\'b\',\'c\'],[\'d\',\'e\',\'f\']]合并为[\'a\',\'b\',\'c\',\'d\',\'e\',\'f\']

admin 更改状态以发布 2023年5月22日
0
0 Comments

使用+运算符可以将列表连接起来。

因此

total = []
for i in [['a','b','c'],['d','e','f']]:
    total += i
print total

0
0 Comments

使用列表推导式:

ar = [['a','b','c'],['d','e','f']]
concat_list = [j for i in ar for j in i]

0