如何在Python中压缩两个列表列表? [英] How to zip two lists of lists in Python?
本文介绍了如何在Python中压缩两个列表列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个列表,每个列表具有相等数量的项目.这两个列表如下所示:
I have two lists of lists that have equivalent numbers of items. The two lists look like this:
L1 = [[1, 2], [3, 4], [5, 6]]
L2 =[[a, b], [c, d], [e, f]]
我正在寻找一个看起来像这样的列表:
I am looking to create one list that looks like this:
Lmerge = [[1, 2, a, b], [3, 4, c, d], [5, 6, e, f]]
我正尝试使用zip()
这样的东西:
I was attempting to use zip()
something like this:
for list1, list2 in zip(*L1, *L2):
Lmerge = [list1, list2]
合并两个列表列表的最佳方法是什么?预先感谢.
What is the best way to combine two lists of lists? Thanks in advance.
推荐答案
>>> map(list.__add__, L1, L2)
[[1, 2, 'a', 'b'], [3, 4, 'c', 'd'], [5, 6, 'e', 'f']]
这篇关于如何在Python中压缩两个列表列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文