Python set: isdisjoint()

masiarek

New member
Joined
Dec 12, 2021
Messages
3
https://docs.google.com/document/d/1jabPCNDI-OtCBxaEP1HnbpsJsjy4PWhvdDvN73mI0gA/edit?usp=sharing
context Python set: isdisjoint()

I am not expecting 2 to be in end result of this program
# test symmetric difference
s1 = {0, 1, 2, 3}
s2 = {2, 3, 4}
s3 = {2, 5}

print(s1 ^ s2 ^ s3) # result {0, 1, 2, 4, 5} - why is 2 in the end result? what am i missing?
zppRxJshEqEjGfZQzwegUnhDEmPhHwCIyoHeW55KW-1lT_L-cVoQkjV8m1hO237t6Y5lU8C93W3mohZxwDKZYIbI9V8ORWYqpwv577xroMJTHalgsXY48Wir8xjZjY1qNtlGGVO2
 
Here is a general statement (provable by induction) : [imath]x \in \wedge_k s_k[/imath] if and only if [imath]x[/imath] belongs to an odd number of [imath]s_k[/imath]. I.e., every time you add another set containing [imath]x[/imath] to a symmetric difference the following happens:
  • [imath]x[/imath] is added to the result if it was not already there
  • [imath]x[/imath] is removed from the result if it was already there.
 
https://docs.google.com/document/d/1jabPCNDI-OtCBxaEP1HnbpsJsjy4PWhvdDvN73mI0gA/edit?usp=sharing
context Python set: isdisjoint()

I am not expecting 2 to be in end result of this program
# test symmetric difference
s1 = {0, 1, 2, 3}
s2 = {2, 3, 4}
s3 = {2, 5}

print(s1 ^ s2 ^ s3) # result {0, 1, 2, 4, 5} - why is 2 in the end result? what am i missing?
zppRxJshEqEjGfZQzwegUnhDEmPhHwCIyoHeW55KW-1lT_L-cVoQkjV8m1hO237t6Y5lU8C93W3mohZxwDKZYIbI9V8ORWYqpwv577xroMJTHalgsXY48Wir8xjZjY1qNtlGGVO2
maybe the keyword here '*two* sets'View attachment 30156
That;'s right.

Just evaluate one step at a time: s1^s2^s3 = (s1^s2)^s3, so, first, what is s1^s2?
 
Top