[英]Remove multiple dictionary value from a list using Python
My data is as follow我的数据如下
dd=[{'id':'aa','age':22,'data':{},'background':{}},
{'id':'bb','age':23,'data':{},'background':{}},
{'id':'cc','age':24,'data':{},'background':{}},
{'id':'dd','age':25,'data':{},'background':{}},
{'id':'ee','age':26,'data':{},'background':{}}
]
How to remove several responses based on id?如何根据 id 删除多个响应? I have almost 100 responses that need to be removed.
我有将近 100 个回复需要删除。
As example:例如:
id = ' aa bb cc '
Use list comprehension to filter out the data you do not want.使用列表理解过滤掉不需要的数据。 However, you should not use the name
id
但是,您不应使用名称
id
dd = [item for item in dd if item['id'] not in id]
您还可以在此处使用filter和lambda函数,
dd = list(filter(lambda x : x["id"] not in a, dd))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.