mlist = [{'sid':'501','7月': 9000,'8月':9500,'9月':9200},
{'sid':'502','7月': 8000,'8月':8500,'9月':8200},
{'sid':'503','7月': 7000,'8月':7500,'9月':7200}]
res_dict = {} # 存放结果字典
res_list = [] # 存放结果列表
index_key = ""
for it in mlist:
for chi in it.keys():
if chi!="sid":
res_list.append(it[chi])
else:
index_key = it[chi]
res_dict[index_key] = res_list
res_list = []
print(res_dict)
python---提取列表里的字典,在生成一个字典
猜你喜欢
转载自blog.csdn.net/qq_42363032/article/details/104605243
今日推荐
周排行