>>> l=[1,2,3,4]>>> keys=['a','b','c','d']>>> zip(keys,l)<zip object at 0x000001E0AFA327C8>>>> dict(zip(keys,l)){'a': 1, 'b': 2, 'c': 3, 'd': 4}>>> list(zip(keys,l))[('a', 1), ('b', 2), ('c', 3), ('d', 4)]# 若参数列表的长度不一样,则以最短长度为准>>> m=[1,2,3]>>> list(zip(keys,m))[('a', 1), ('b', 2), ('c', 3)]# 分解zip>>> a1,a2=zip(*zip(keys,l))>>> a1('a', 'b', 'c', 'd')>>> a2(1, 2, 3, 4)>>>
>>> import json>>> l=[[1,2,3,4],[5,6,7,8],[9,10,11,12]]>>> keys=['a','b','c','d']>>> list_json=[dict(zip(keys,item)) for item in l]# indent缩进量,ensure_ascii=False支持中文>>> str_json=json.dumps(list_json,indent=2, ensure_ascii=False)>>> print(str_json)[ { "a": 1, "b": 2, "c": 3, "d": 4 }, { "a": 5, "b": 6, "c": 7, "d": 8 }, { "a": 9, "b": 10, "c": 11, "d": 12 }]