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, 2019 in Python by Mishti
• 480 points
1,874 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, 2019 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, 2019 in Python by Sagar
• 130 points
1,518 views