python - 如何将来自不同列表的数据合并到各自的行中?

标签 python list row

以我为例:

list1 = [0, 1, 2, 3]
list2 = [8, 7, 1, 7]
list3 = [1, 2, 3, 4]
combinedlist=[]

我如何确保值将在各自的行中加在一起,以便 combinedlist 的输出将是:

[9, 10, 6, 14]

最佳答案

list1 = [0, 1, 2, 3]
list2 = [8, 7, 1, 7]
list3 = [1, 2, 3, 4]

out = [sum(v) for v in zip(list1, list2, list3)]
print(out)

打印:

[9, 10, 6, 14]

关于python - 如何将来自不同列表的数据合并到各自的行中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62978212/

相关文章:

html - 使交替的 CSS 表格行样式在 Internet Explorer 中工作

php - 如何更新表行并在行字段中添加+1?

python - 在 Panda Python 中使用偏差和均值函数

python - 无法在python中导入beautifulsoup

python - Python 中的元组赋值,这是 Python 中的错误吗?

java - Java 中 String 列表和 String[] 列表,或 T 列表和 T[] 列表的通用方法

python - 在数据框中搜索子字符串并替换它

python - 杀死所有锁定文件的进程

c - 在 C 文件中使用 List.h,Ubuntu10.10

c# - 在 c# 中从数据库检索数据到 dataGridView 时出现空行