假设我有一个对象列表,我想删除具有相同副本的对象,然后保留具有idpublic: true
recipes = [
{'id': 1, 'public': True},
{'id': 1, 'public': False},
{'id': 2, 'public': False},
{'id': 3, 'public': True},
{'id': 3, 'public': False}
]
list_ = []
[list_.append(r) for r in recipes if r.id not in list_]
print(list_)
要添加的第二个条件是什么?
想要的结果:
recipes = [
{'id': 1, public: True},
{'id': 2, public: False},
{'id': 3, public: True},
]
蟒
慕尼黑的夜晚无繁华
梵蒂冈之花
月关宝盒
相关分类