如何在 Python 中压缩两个列表列表? [英] How to zip two lists of lists in Python?

查看:30
本文介绍了如何在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆