a = [dict1, dict2, dict3]
b = [dict1, dict2, dict4, dict5, dict6]
c = dicts_from_a_not_in_b = [x for x in a if x not in b]
d = dicts_from_b_not_in_a = [x for x in b if x not in a]
a = [dict1, dict2, dict3]
b = [dict1, dict2, dict4, dict5, dict6]
def find_uncommon_elements(list1, list2):
list3 = []
for item in list1:
if item not in list2:
list3.append(item)
return list3
c = find_uncommon_elements(a,b)
d = find_uncommon_elements(b,a)
一个简单的O(n^2)解决方案:
在我看来,在这种情况下使用集合是非常合理的。在
只需用list(c)和list(d)将集合包装起来,就可以将集合转换为list
以下是重用函数的另一种方法:
编写一个函数有助于以后使用不同的字典列表再次使用它,而不必重写整个函数。在
这将返回:
^{pr2}$相关问题 更多 >
编程相关推荐