Lets say I have these lists:
key_list = [key1, key2,.....,key20]
val_list = [[val1, val2,...,val20],[val1, val2,...,val20], [val1, val2,...,val20],....,[val1, val2,...,val20]]
How can I make it so that I can use the first list as keys and then iterate through each list in the second list and make a dictionary like this:
{
"rows": [
{
"key1": "val1",
"key2": "val2",
.
.
.
"key20": "val20"
},
{
"key1": "val1",
"key2": "val2",
.
.
.
"key20": "val20"
},
{
"key1": "val1",
"key2": "val2",
.
.
.
"key20": "val20"
},
{
"key1": "val1",
"key2": "val2",
.
.
.
"key20": "val20"
},
.
.
.
{
"key1": "val1",
"key2": "val2",
.
.
.
"key20": "val20"
}
]
}
I tried this one but it is not giving me the desired output:
data = []
for row in val_list:
t = dict.fromkeys(key_list, row)
data.append(t)
print(json.dumps(data, indent=4))