首页 > 解决方案 > 如何在将元素 1 乘 1 时连接两个列表

问题描述

如何在 Python 中逐一获取元素时连接两个列表?

例子:

listone = [1, 2, 3]
listtwo = [4, 5, 6]

预期结果:

>>> joinedlist
[1, 4, 2, 5, 3, 6]

标签: pythonlist

解决方案


zip列表和展平itertooos.chain

from itertools import chain

list(chain.from_iterable(zip(listone, listtwo)))
[1, 4, 2, 5, 3, 6]

推荐阅读