This question already has answers here:
How can I compare two lists in python and return matches
                                
                                    (19个回答)
                                
                        
                                5年前关闭。
            
                    
给出两个清单

a = [1,2,3,4,5]
b = [2,4,6,7]


输出类似元素

c = [2,4]


是否有API可以比较和提取两个列表中的相似元素?通过逐个元素地比较可以做到这一点,但是我想知道是否已经有API。

最佳答案

print set(a).intersection(set(b))


使用交集获得两个列表中的公共元素

关于python - 从两个列表中提取相同的元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24038387/

10-10 01:08
查看更多