简体   繁体   English

如何找到 python 中两个集合的 AND 运算的余数

[英]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.

相关问题 在 Python 中查找两个日期之间的年差,余数以天表示 - Find difference between two dates in years, with the remainder expressed in days, in Python Python 3.x-如何在两个字符串中查找字符集的交集 - Python 3.x - How to find the intersection of the sets of characters in two strings python算法:如何有效地找到两个整数集是否相交? - python algorithm: how to efficiently find if two integer sets are intersected? Python - Regex - 如何在两组字符串之间查找字符串 - Python — Regex — How to find a string between two sets of strings 如何在python 2.7中轻松实现类似C的模(余数)操作 - How to easily implement C-like modulo (remainder) operation in python 2.7 如何在pandas中的两组列上执行元素操作 - How to perform element wise operation on two sets of columns in pandas 如何在pandas中找到两个数据集的对齐方式 - How to find the alignment of two data sets in pandas 我如何在不使用集合的情况下在python中找到两个列表的交集 - How would I find the intersection of two lists in python without using sets 如何在 python 中的循环下加速包括交集和并集在内的操作 - How to accelerate the operation including intersection and union of sets under the loops in python 如何在不使用集合的情况下在 Python 的两个字典值列表中找到公共元素? - How to find the common elements inside two list of values of dictionary in Python without using sets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM