th = ["ID", "LABEL", "DESC"]
td = [[1001, "testLabel1", "testDesc1"],[1002, "testLabel2", "testDesc2"]]
result = [{}]
#unpack sublists in td, pass iterables to combine with zip, put in a list
transposed_data = list(zip(*td))
print(transposed_data)
#[(1001, 1002), ('testLabel1', 'testLabel2'), ('testDesc1', 'testDesc2')]
#values uniform in each tuple
#enumerate th to get index and value
for i, header in enumerate(th):
result[0][header] = list(transposed_data[i])
print(result)
#[{'ID': [1001, 1002], 'LABEL': ['testLabel1', 'testLabel2'], 'DESC': ['testDesc1', 'testDesc2']}]
# each key with related values
Editor is loading...