Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
IIUC,您可以创建 a 的类的集合并循环 b 以仅保留具有新类的元素:
集合
existing = set(d['class'] for d in a) # {'class1'} c = a + [d for d in b if d['class'] not in existing]
输出:
[{'class': 'class1', 'subclass': 'subclass1'}, {'class': 'class3', 'subclass': 'subclass3'}]
IIUC, you can create a set of a's classes and loop over b to keep onle the elements with new classes:
set
output:
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(1)
IIUC,您可以创建 a 的类的
集合
并循环 b 以仅保留具有新类的元素:输出:
IIUC, you can create a
set
of a's classes and loop over b to keep onle the elements with new classes:output: