【发布时间】:2021-01-23 14:50:50
【问题描述】:
例如,我有两个列表 a 和 b,其中有两个或多个列表(取决于我的输入) 我希望输出是 a[0] 和 b[0] 和 ...
的总和n = int(input())
for i in range(n):
x = list(map(int, input().split()))
a.append(x)
for i in range(n):
x2 = list(map(int, input().split()))
b.append(x2)
现在例如 n = 2,之后我们将有 4 个输入 喜欢:
these will be appended to a
1 2 3
4 5 6
and these two will be appended to b
2 3 4
5 6 7
现在我希望我的输出是
3 5 7
9 11 13
as you can see a[0] + b[0]
and a[1] + b[1]
但我希望我的代码输出这样,即使我给我的 n 输入一个大于 2 的数字 例如,如果我给我的 n 输入 3,我将在 a 和 b 中有 3 个索引,它们都是列表,我希望输出与最后一个例子一样工作,
example
for n = 3
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
b = [[3, 2, 1], [4, 5, 6], [9, 8, 7]]
【问题讨论】:
-
你能添加给定示例的预期输出吗?
标签: python arrays python-3.x string list