Not the most efficient one, but by far the most obvious way to do it is:
(不是最有效的方法,但到目前为止最明显的方法是:)
>>> a = [1, 2, 3, 4, 5]
>>> b = [9, 8, 7, 6, 5]
>>> set(a) & set(b)
{5}
if order is significant you can do it with list comprehensions like this:
(如果订单很重要,你可以使用这样的列表推导来做到这一点:)
>>> [i for i, j in zip(a, b) if i == j]
[5]
(only works for equal-sized lists, which order-significance implies).
((仅适用于大小相同的列表,其中含义为重要性)。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…