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]


沒有留言:

張貼留言

[Linux 常見問題] How to set a file size limit for a directory?

Source From   Here   Question   I   have a directory on my system which is used for a specific reason by applications and users , but I   d...