a = [1,2,3,4,5]
b = [1,3,5,6]
c = a and b
print c
Run Code Online (Sandbox Code Playgroud)
实际产出:[1,3,5,6]
预期产量:[1,3,5]
我们如何在两个列表上实现布尔AND操作(列表交集)?
例如,我有两个列表
A = [6, 7, 8, 9, 10, 11, 12]
subset_of_A = [6, 9, 12]; # the subset of A
the result should be [7, 8, 10, 11]; the remaining elements
Run Code Online (Sandbox Code Playgroud)
在python中是否有内置函数来执行此操作?