我这里有一个清单
arg_list = ['arg1','arg2','arg3','arg4']
value_list = [[1,2,3,4],[5,6,7,8],[3,5,2,4]]
我想将其转换为dict对象列表
[{'arg1':1,'arg2':2,'arg3':3,'arg4':4},{'arg1':5,'arg2':6,'arg3':7,'arg4':8}....etc]
我怎样才能以最pythonic的方式完成这项工作?
答案 0 :(得分:6)
In [3]: [dict(zip(arg_list, e)) for e in value_list]
Out[3]:
[{'arg1': 1, 'arg2': 2, 'arg3': 3, 'arg4': 4},
{'arg1': 5, 'arg2': 6, 'arg3': 7, 'arg4': 8},
{'arg1': 3, 'arg2': 5, 'arg3': 2, 'arg4': 4}]