Filter a dict of dict

前端 未结 4 1169
不思量自难忘°
不思量自难忘° 2020-12-19 16:01

I new in Python and I am not sure it is a good idea to use dict of dict but here is my question. I have a dict of dict and I want to filter by the key of the inside dict:

4条回答
  •  甜味超标
    2020-12-19 16:31

    field = 'id1'
    dict( (k,{field: d[field]}) for k,d in a.items() if field in d)
    

提交回复
热议问题