目录
python 字典过滤筛选数据
a = {'m': {'type': 'A', 'id': 1}, 'a': {'type': 'B', 'id': 2}, 'A': {'type': 'C', 'id': 3}, 'f': {'type': 'D', 'id': 4}, 'g': {'type': 'D', 'id': 5}}
allowed_keys = ['A', 'D']
sel_res=dict(filter(lambda x: x[1]['type'] in allowed_keys, a.items()))
for key in sel_res:
print(key,sel_res[key])