While learning Python from http://www.learnpython.org/en/Sets I encountered the notion of symmetric_difference between sets. I thought it gave the same output as 'exclusive or' operations on sets. How is it different?
What is Python symmetric_difference and how is it different from XOR operation?
4.5k Views Asked by Huxwell At
2
There are 2 best solutions below
2
mik01aj
On
Yes, it is pretty much the same, just XOR is an operation on booleans, and symmetric_difference is an operation on sets. Actually, even your linked documentation page says this:
To find out which members attended only one of the events, use the "symmetric_difference" method
You can also see this more detailed mathematical explanation about relationship between logical XOR and symmetric difference on sets.
Related Questions in PYTHON
- new thread blocks main thread
- Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID
- Display images on Django Template Site
- Difference between list() and dict() with generators
- How can I serialize a numpy array while preserving matrix dimensions?
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Why is my program adding int as string (4+7 = 47)?
- store numpy array in mysql
- how to omit the less frequent words from a dictionary in python?
- Update a text file with ( new words+ \n ) after the words is appended into a list
- python how to write list of lists to file
- Removing URL features from tokens in NLTK
- Optimizing for Social Leaderboards
- Python : Get size of string in bytes
- What is the code of the sorted function?
Related Questions in SET
- Removing duplicates from arraylist using set
- Order-independent Hash Algorithm
- How to count 2 different duplicate values in array - Swift
- CMD specifying columns to save?
- comparison of two sets when repeated in r
- How to use set(data structure) in mongodb console?
- Reversing logic of a product-country mapping
- Storing data in sorted manner in a HashSet
- Generate all combinations of strings and their substrings in a set -- python
- How to access class data in a set of pointers to that class
- Scala set element uniqueness: What to implement for comparison of user defined classes?
- java.util.Set add and remove method signature difference
- retrieve all the smallest strings from a set in python
- Setting a String Variable in SSIS
- Setting a robocopy log file to a variable
Related Questions in XOR
- == vs equals vs XOR benchmark
- How to swap two strings?
- How to get the XOR key from a python file?
- Function to XOR two 128 bits. How do I generate 128 bit values?
- Maximum xor of a range of numbers
- Maximum Value of XOR in a range?
- Implementing XOR-MAPPED-ADDRESS attribute on STUN server
- How to XOR two string arrays in Golang?
- What type of neural network to use?
- swap two variables in verilog using XOR
- C++ xor between 2 strings Null CBC
- XNOR comparing with XOR Artificial Neural Network
- How to XOR numbers together then extract a number
- What is encryption IV for?
- Printing result of a bitwise XOR in C
Related Questions in SYMMETRIC-DIFFERENCE
- Trying to solve symmetric difference using Javascript
- Can a RegEx with negative lookahead be represented as a finite automaton?
- symmetric_difference Output as Two Separate Lists
- Python: Symmetrical Difference Between List of Sets of Strings
- Python: best way to find out from which set the results of `symmetric_difference` are from?
- Efficiently compute xor / symmetric difference of many sets (list of sets)
- How to find symmetrical difference using JavaScript?
- What is the best effective way to get symmetric difference between two strings(in python)?
- Why are the symmetric_difference and intersection operations for the Shapely.Geometry library apparently inconsistent?
- Locally symmetric difference in sql
- How can the symmetric difference between two lists be obtained?
- Function to find symmetric difference (opposite of intersection) in R?
- Can I use update method of set in Python to merge two set (x-y) and (y-x)?
- How to efficiently find identical indices in multiple dataframes
- Python sets: difference() vs symmetric_difference()
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
There is no difference. XORing sets works by calling the
symmetric_differencefunction. This is from the implementation of sets in sets.py:As you can see the XOR implementation makes sure that you are indeed working on sets only, but otherwise there are no differences.