利用Python的set类型可以进行集合之间的操作,可以简单地比较两个集合列表是否相等。
示例代码: list1 = [{'a', 'b'}, {'c', 'd'}, {'e', 'f'}] list2 = [{'a', 'b'}, {'c', 'd'}, {'e', 'f'}]
set1 = set([frozenset(i) for i in list1]) set2 = set([frozenset(i) for i in list2])
if set1 == set2: print("两个集合列表相等") else: print("两个集合列表不相等")
上一篇:比较两个集合后排序查询
下一篇:比较两个集合列表