leo*_*hel 3 python arrays dictionary elementwise-operations
从这些数组:
t = ["A","B","C"]
a = [1,2,3]
b = [4,5,6]
c = [7,8,9]
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得这样的列表
[
{ 'A':1, 'B':4, 'C':7},
{ 'A':2, 'B':5, 'C':8},
{ 'A':3, 'B':6, 'C':9},
]
Run Code Online (Sandbox Code Playgroud)
这样在JSON中转储更有用吗?
你可以这样做:
t_data = [a, b, c]
[{u:v for u, v in zip(t, xs)} for xs in zip(*t_data)]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52 次 |
| 最近记录: |