# 将mlist中,字典的键和值取出,返回新字典mdict中
# mdict的结构如下:
# {'501':[9000,9500,9200],'502':[8000,8500,8200],'503':[7000,7500,7200]
'''
总的思路:生成2个列表,分别是
ls1 = [‘501’,’502’,’503’]
ls2 = [[9000,9500,9200],[8000,8500,8200],[7000,7500,7200]]
然后用zip方法打包,返回给dict方法
'''
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}]
ls1 = []
ls2 = []
for i in mlist:
ls1.append(i.get('sid'))
ls2.append([x for x in i.values() if x != '501' and x != '502' and x != '503'])
mdict = dict(zip(ls1,ls2))
print(mdict)
ls2列表生成式,也可以使用成员运算符not in
ls2.append([x for x in i.values() if x not in ['501','502','503']])