Exclusive values from two Sets in Python

0 votes
In my program, I have two sets which may contain some common values. I want to identify only those values from the two sets which are not common in both (something like an exclusive OR). How can I achieve this?
Mar 26 in Python by Mishti
• 480 points
50 views

1 answer to this question.

0 votes

There is a direct function available to achieve this - symmetric_difference

Let's say, we have two sets A & B with values as-

A={1,2,3,4} & B={3,4,5,6} and C be the set containing values which are either in A or B but not both. The values in C can be computed as shown below-

Hope this helps.

answered Mar 27 by Mugdha
• 600 points

Related Questions In Python

+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20 in Python by Sagar
• 130 points
102 views
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
198 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
110 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
858 views
0 votes
2 answers

Extracting data from a JSON file in Python

Here is what i found and was ...READ MORE

answered Nov 27, 2018 in Python by Rupali
10,786 views
0 votes
0 answers

what is a bitwise operator in python?

can you show some operations using bitwise ...READ MORE

Apr 8 in Python by Waseem
• 4,480 points
38 views
0 votes
0 answers

what is the logical AND operator in python?

how do i use it in a ...READ MORE

Apr 12 in Python by Waseem
• 4,480 points
40 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 412 views
0 votes
1 answer

Python - Use unique element from a set

The best way to achieve this by ...READ MORE

answered Mar 27 in Python by Mugdha
• 600 points
52 views