简体   繁体   English

使用 Python 从列表中删除多个字典值

[英]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]

您还可以在此处使用filterlambda函数,

dd = list(filter(lambda x : x["id"] not in a, dd))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Python3 中使用 filter() 从字典值列表中删除列表 - Remove a list from dictionary value lists using filter() in Python3 使用 python 从字典和列表中删除 nan 值 - Remove nan value from dictionary and list using python 从[list]字典python中删除多个值 - Remove multiple values from [list] dictionary python python-如果字典键等于某个值,则从列表中删除字典 - python - remove a dictionary from a list if dictionary key equals a certain value 如何从 Python 列表中删除多个(键、值)条目 - 有序字典 - How to remove multiple (key,value) entries from a Python List - Ordered Dictionary Python:如果列表项是字典中给定值的键,则将其删除 - Python: Remove list item if it is key for a given value from dictionary Python 字典 - 从字典列表中删除字典 - Python dictionary - Remove dictionary from list of dictionaries 在python中使用lambda和filter从字典列表中过滤字典值 - Filtering a dictionary value from a list of dictionary using lambda and filter in python 使用python从txt文件中删除字典中的多个键 - Remove multiple keys from dictionary from txt file using python 如何从字典列表中删除字典(使用给定值)? - How to remove a dictionary from a list of dictionaries (using a given value)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM