Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Union, Intersection, and Difference

Johnny Swanny on March 14, 2020

Really liking the breakdown of this.

Sciencificity on April 27, 2020

Hi James, I think that symmetric_difference() only takes one argument since it does not make sense when you apply it to multiple arguments. This is due to the left to right nature of the operator. The in between sets used with ^ can introduce elements that appeared in previous sets but were discarded by the previous use of ^. E.g using the example we used previously we would have the below:

a = {1,2,3,4}
b = {2,3,4,5}
c = {3,4,5,6}
d = {4,5,6,7}
print(a ^ b ^ c ^ d) # a ^ b -> {1,5} ^ c -> {1,3,4,6} ^ d -> {1,3,5,7}

{1, 3, 5, 7} # result ... but 3, 5 occur in multiple sets

Also if we amend the example used in the video slightly (add a 2 in last set):

a = {1,2,3,4,5}
b = {10,2,3,4,50}
c = {1,2,50,100}
print(a ^ b ^ c)

{2, 100, 5, 10} # result

Kumaran Ramalingam on Aug. 16, 2020

Hi James, It was really useful for me to breakdown things and learn

Become a Member to join the conversation.