【发布时间】:2021-04-16 21:56:30
【问题描述】:
我有多个数组,我想找到它们之间的交集我尝试了以下代码。
my_lists = [['Finish', 'Purpose', 'Form', 'Series', 'Tiles Type', 'Finishing'], ['Color', 'Thickness', 'Usage/Application', 'Brand', 'Marble Type', 'Material'], ['Color', 'Brand', 'Finishing', 'Origin', 'Marble Type', 'Thickness'], ['Thickness', 'Form', 'Size', 'Series', 'Usage/Application', 'Finishing'], ['Thickness', 'Material Grade', 'Size', 'Usage/Application', 'Material'], ['Usage/Application', 'Form', 'Finishing', 'Brand', 'Material', 'Shape'], ['Application Area', 'Form', 'Finishing', 'Brand', 'Color', 'Coverage Area'], ['Usage/Application', 'Marble Type', 'Thickness', 'Brand', 'Form'], ['Unit Size (mm X mm)', 'Marble Type', 'Thickness', 'Finishing', 'Usage', 'Brand'], ['Marble Type', 'Unit Size (mm X mm)', 'Usage', 'Thickness', 'Color'], ['color'], ['Thickness', 'Size', 'Usage/Application', 'Series', 'Finish', 'Marble Type'], ['Thickness', 'Usage/Application', 'Brand', 'Color', 'Marble Type', 'Unit Size (mm X mm)'], ['Color', 'Marble Type', 'Usage'], ['Thickness', 'Size', 'Material', 'Finish', 'Packaging Size', 'Packaging Type'], ['Color', 'Material', 'Thickness', 'Usage/Application', 'Back Lit', 'Brand'], ['Material', 'Pattern', 'Shape'], ['Form', 'Application Area', 'Material', 'Thickness', 'Colour', 'Finishing'], ['Color', 'Usage/Application', 'Brand', 'Series'], ['Color', 'Material', 'Thickness', 'Usage/Application', 'Brand', 'Surface Finish'], ['Brand', 'Color', 'Usage/Application', 'Thickness', 'Size', 'Finish'], ['Form', 'Material', 'Usage', 'Marble Type', 'Thickness', 'Finishing'], ['Form', 'Color', 'Marble Type', 'Unit Size', 'Features', 'Coverage Area'], ['Usage', 'Form'], ['Finish', 'Application Area', 'Purpose', 'Thickness', 'Pattern'], ['Usage/Application', 'Finishing', 'Material', 'Brand', 'Size', 'Category Type'], ['Usage/Application', 'Size', 'Color', 'Marble Type', 'Features', 'Finishing'], ['Marble Type', 'Surface Finishing', 'Stone Form', 'Usage'], ['Brand', 'Material', 'Finish', 'Thickness', 'Size']]
print(set.intersection(*map(set,list(my_lists ))))
但我得到一个空集
set()
我真正想要的是在所有列表中找到共同的元素
【问题讨论】:
标签: python arrays data-structures intersection