假设我有两个长度相等的数组,如下所示:A = [0 0 1 0 1 3 4 3]
B = [1 2 1 3 4 1 2 3]我想要一个连接相应值的输出,例如:[0:1 0:2 1:1 0:3 1:4 3:1 4:2 3:3]
1 回答
慕码人2483693
TA贡献1860条经验 获得超9个赞
A = [0, 0, 1, 0, 1, 3, 4, 3]
B = [1, 2, 1, 3, 4, 1, 2, 3]
joined = [{a:b} for a, b in zip(A, B)] # list of dicts
print(joined)
输出:
[{0: 1}, {0: 2}, {1: 1}, {0: 3}, {1: 4}, {3: 1}, {4: 2}, {3: 3}]
或者,也许:
joined = list(zip(A, B)) # list of tuples
print(joined)
输出:
[(0, 1), (0, 2), (1, 1), (0, 3), (1, 4), (3, 1), (4, 2), (3, 3)]
添加回答
举报
0/150
提交
取消