Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.
The
symmetric_difference_update()
method in Python for two elements, A and B, is used to return the set of elements that are contained in A and B, but not common in both of them, and it also updates the set calling it. In other words, it is used to return the symmetric difference of two sets and update the set calling it.
A.symmetric_difference_update(B)
Parameter | Description |
A | This is required. It is one of the sets with which we want to find a symmetric difference with the second set. This is the updated set. |
B | This is required. It is one of the sets with which we want to find a symmetric difference with the second set. |
The symmetric_difference_update()
method returns no value. Rather, it updates the set that calls it.
Now let’s create two sets, A and B, and then use the symmetric_difference_update()
method to obtain the update from both sets.
A = {1, 2, 3, 4}B = {2, 3, 6, 5}A.symmetric_difference_update(B)# to return the updated set Aprint('The symmetric difference between A and B is:', A )# to return the set Bprint('B still remains:', B)
A
.B
.symmetric_difference_update()
method to take the symmetrical difference between the two sets, A and B.A
, which contains elements found in both sets, but are not common to both of them.B
.Note: We can see that the return value of the
symmetric_difference_update()
method is actually none (that is, no result). However, it only updates the value of setA
.
Let’s try out another example in the code below.
A = {'a','b','c','d'}B = {'a','f','g'}A.symmetric_difference_update(B)# to return the updated set Aprint('The symmetric difference between A and B is:', A )# to return the set Bprint('B still remains:', B)
The "symmetric-difference-update()
method returns the symmetric difference between two sets, while simultaneously updating the set that called it.
RELATED TAGS
CONTRIBUTOR
Grokking Modern System Design Interview for Engineers & Managers
Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.