且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何找到列表列表中的公共元素?

更新时间:2022-05-27 22:04:27

您正在查找所有子列表的集合交集,并且您应该用于集合操作的数据类型是一组:

You are looking for the set intersection of all the sublists, and the data type you should use for set operations is a set:

result = set(p[0])
for s in p[1:]:
    result.intersection_update(s)
print result