headers = ['id', 'product', 'plan']
values = [['1', 'abc', '123'],['2', 'efg', '1234'],['3', 'ijk', '890']]
data = []
for entries in values:
data.append(dict(itertools.izip(headers, entries)))
答案 0 :(得分:1)
这种类型的数据抽象的常见模式是一列字典,这些字典可以轻松转换为JSON(对象数组)。
import pprint
headers = ['id', 'product', 'plan']
values = [
['1', 'abc', '123'],
['2', 'efg', '1234'],
['3', 'ijk', '890'],
]
list_of_dicts = [dict(zip(headers, row)) for row in values]
pprint.pprint(list_of_dicts)
输出
[{'id': '1', 'plan': '123', 'product': 'abc'},
{'id': '2', 'plan': '1234', 'product': 'efg'},
{'id': '3', 'plan': '890', 'product': 'ijk'}]