Consider the following Python code snippet.
A={"this","that"}
B={"that","other"}
C={"other","this"}
while "other" in C:
if "this" in A:
A,B,C=A-B,B-C,C-A
if "that" in B:
A,B,C=C|A,A|B,B|CWhen the above program is executed, at the end, which of the following sets contains "this"?
Answer
(B)
Explanation
Each tuple assignment evaluates its whole right-hand side with the old sets before assigning anything.
- Pass 1, first
if:A={"this"},B={"that"},C={"other"}. - Pass 1, second
if("that"is inB):A={"other","this"},B={"this","that"},C={"that","other"}. - Pass 2:
"other"is still inCand"this"is inA, soA={"other"},B={"this"},C={"that"}. Now"that"is not inB, so the secondifis skipped.
"other" is no longer in C, so the loop stops. Only B contains "this".
Answer: B