+ 1

Python Set Symmetric Difference

A = {1, 2, 3, 4, 5} B = {1,4, 5, 6, 7, 8} C = {3,1} print(A^B^C) OUTPUT: {1, 2, 6, 7, 8} Why 1 is there? It is common so it should be eliminated.

1st Jun 2019, 3:36 PM
harshit
harshit - avatar
2 Antworten
+ 5
It's the same as print(A^(B^C)) (or maybe (A^B)^C if it's left associated, I don't know) Try this and it'll make sense: D = B^C print(D) print(A^D)
1st Jun 2019, 3:45 PM
Anna
Anna - avatar
+ 3
harshit For the first {1, 2, 3, 4, 5} ^ {1,4, 5, 6, 7, 8} == {2, 3, 6, 7, 8} (without 1) then {2, 3, 6, 7, 8} ^ {3,1} = {1, 2, 6, 7, 8} So 1 in game again
1st Jun 2019, 3:44 PM
portpass