3

从这些数组中:

t = ["A","B","C"]
a = [1,2,3]
b = [4,5,6]
c = [7,8,9]

我怎样才能获得这样的列表

[
  { 'A':1, 'B':4, 'C':7},
  { 'A':2, 'B':5, 'C':8},
  { 'A':3, 'B':6, 'C':9},
]

以便在 JSON 中转储更有用?

4

1 回答 1

5

你可以这样做:

t_data = [a, b, c]
[{u:v for u, v in zip(t, xs)} for xs in zip(*t_data)]
于 2018-03-21T09:52:33.550 回答