Python has a plethora of in-built methods to make carrying out simple tasks much easier. One such method is symmetric_difference_update()
.
This is used to find the symmetric difference of two sets and it updates the set that calls the method. The elements of that set are passed as an argument.
set1.symmetric_differences_update(set2)
This method requires one set to be passed as a parameter, which it will compare with the set that calls the method.
It is important to note that this returns None
and only updates the set calling it.
x = {'Cats', 'Dogs', 'Elephants', 'Seals'}y = {'Dogs', 'Lions', 'Seals', 'Parrots'}x.symmetric_difference_update(y)print(x)