2017年8月12日 星期六

[ Python 常見問題 ] How to find list intersection?

Source From Here
Question
How can we achieve a boolean AND operation (list intersection) on two lists?

How-To
If order is not important and you don't need to worry about duplicates then you can use set intersection:



For example:
>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
[1, 3, 5]


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...