且构网

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

如何在列表列表中查找公共元素?

更新时间:2022-03-09 06:20:55

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

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