GATE DA 2025 Q47: Python sets in a while loop: which set ends up with "this"?
- Programming, Data Structures and Algorithms
- 2 marks
- MCQ
- −2/3 if wrong
Question
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"?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: B (official GATE 2025 final answer key)
Concept used: Set difference and union, and simultaneous tuple assignment in Python.
First step: Trace the first pass: A−B = {"this"}, B−C = {"that"}, C−A = {"other"}. All three right-hand sides use the old values, because tuple assignment evaluates them first.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2025 DA question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key
More Programming, Data Structures and Algorithms PYQs
- 2025 · Q18Hashing with linear probing: h(x) = 3x mod 10
- 2025 · Q23Python lists: which call gives A = [1, 2, 3, 4, 5, 6]?
- 2025 · Q27When does binary search run in O(log n)?
- 2025 · Q29Insertion sort with exactly two swaps: possible values of x
- 2025 · Q58Shortest paths: which edges cannot be in G?
- 2025 · Q63Python recursion: value of f(15, 10)