【Python】将字典转换为列表 & 利用map()把两个列表合成一个字典
1. 把列表list转换为字典dictionary
a = ['1', '2', '3']
b = ['a', 'b', 'c']
c = dict(map(lambda x, y : [x, y], a, b))
print(c)
#输出结果:
{'1': 'a', '2': 'b', '3': 'c'}
2. 将字典dictionary转换为列表list:
datas = {'1': 'a', '2': 'b', '3': 'c'}
to_list = []
print(type(to_list))
for dic in datas.items():
print(dic)
to_list += dic
print(to_list)
#输出结果:
['1', 'a', '2', 'b', '3', 'c']

浙公网安备 33010602011771号