[英]How to find the remainder of an AND operation on two sets in python
I have two sets of countries, one of which is longer, and I'm trying to find the entries that don't feature in both lists.我有两组国家/地区,其中一组更长,我试图找到两个列表中都没有的条目。
(set(a) & set(b) this code gave me the entries that appear in both. Not(set(a) & set(b)) just returned false. I'm looking for a list (set(a) & set(b) 这段代码给了我出现在两者中的条目。Not(set(a) & set(b)) 只是返回 false。我正在寻找一个列表
In set theory, this is known as the symmetric difference , and in Python, sets have a symmetric_difference
method , so you could use在集合论中,这被称为对称差异,在 Python 中,集合有一个
symmetric_difference
方法,所以你可以使用
set(a).symmetric_difference(set(b))
or, as shorthand或者,作为速记
set(a) ^ set(b)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.