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
36 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
• 580 points

Related Questions In Python

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,710 points
57 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,710 points
62 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
552 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
5,749 views
0 votes
1 answer

Returning values in python

Place your values in a tuple and ...READ MORE

answered Apr 26, 2018 in Python by Nietzsche's daemon
• 4,260 points
14 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
• 3,480 points
20 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
• 3,480 points
24 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 132 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
• 580 points
41 views