python - 如何在将元素 1 乘 1 时连接两个列表
问题描述
如何在 Python 中逐一获取元素时连接两个列表?
例子:
listone = [1, 2, 3]
listtwo = [4, 5, 6]
预期结果:
>>> joinedlist
[1, 4, 2, 5, 3, 6]
解决方案
zip
列表和展平itertooos.chain
:
from itertools import chain
list(chain.from_iterable(zip(listone, listtwo)))
[1, 4, 2, 5, 3, 6]
推荐阅读
- php - 获取 JSON 响应成功状态消息并存储在 php MySQL 中的 DB 中
- python - 使用多个索引从 n 维数组中访问元素的优化方式
- batch-file - 我正在尝试批量创建管理员“登录”,它只是关闭了 cmd
- c - 为什么我的数组以整数而不是浮点数显示
- firebase - Firebase onMessage()未收到消息
- c# - 如何用三元运算符替换 if 语句?
- python - 如何创建不同特征的组合并将它们传递给随机森林分类器?
- selenium-webdriver - 使用 wait.until(ExpectedConditions.visibilityOf(element) 方法获取异常
- python-3.x - 使用文件名作为函数的参数并从另一个列表中删除一个列表
- r - 通过使用 FOR 循环删除缺失值,查找 R 数据集中列的平均值