chapter
    Python Data Structures: Lists, Sets and Dictionaries PYQs for GATE DA

    Solve 2+ Python Data Structures: Lists, Sets and Dictionaries previous year questions for GATE DA with answers and detailed solutions. Free sample questions b

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2025 PYQ
    Level 4: Challenger
    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|C

    When the above program is executed, at the end, which of the following sets contains "this"?
    Question 2
    2025 PYQ
    Level 3: Exam Standard
    Consider the following Python declarations of two lists.

    A=[1,2,3]
    B=[4,5,6]

    Which one of the following statements results in ?
    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Python Data Structures: Lists, Sets and Dictionaries PYQs for GATE DA

    Solve 2+ Python Data Structures: Lists, Sets and Dictionaries previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Lists and Sets for Code Tracing

    Chapter Roadmap: Lists and Sets for Code Tracing

    Orientation Level 1 60 sec Importance 0.58 Toughness 0.20

    This chapter is about predicting the final state of Python data structures after a sequence of operations.

    Topic 1: Python List Operations and In-Place Updates

    Focus on:

    • Lists as ordered, mutable sequences.
    • Indexing and slicing.
    • append, extend, insert, pop, remove, sort, reverse.
    • Concatenation with +.
    • Augmented assignment with +=.
    • Aliasing: when two names refer to the same list.
    • Copying: when a separate list is created.

    Topic 2: Python Set Operations and Membership Tracing

    Focus on:

    • Sets as unordered collections of unique elements.
    • Membership testing using in.
    • Union, intersection, difference, and symmetric difference.
    • Mutating set operations.
    • Tracing loops that repeatedly update sets.
    • Simultaneous assignment such as A, B = A - B, B - A.

    Core Question to Keep Asking

    1. Is the same object being changed?
    2. Is a new object being created?
    3. Which variable names now point to which object?
    4. What will the next loop condition or membership test see?

    If you can answer these four questions, most list and set tracing problems become mechanical.

    Lists Are Ordered, Mutable Boxes

    Lists Are Ordered, Mutable Boxes

    Concept Level 2 75 sec Importance 0.60 Toughness 0.25

    A Python list is an ordered collection. The position of each item matters, and the list can be changed after creation.

    items = [10, 20, 30]

    Basic Properties

    PropertyMeaning
    Ordered[1, 2, 3] is different from [3, 2, 1]
    MutableElements can be changed, added, or removed
    Duplicates allowed[1, 1, 2] is valid
    Indexed by positionFirst item is index 0, last is index -1

    Common Operations

    x = [10, 20, 30]
    x[0] = 5          # replace item
    x.append(40)      # add one item at end
    x.insert(1, 15)   # insert at index 1
    x.pop()           # remove and return last item
    x.remove(20)      # remove first occurrence of 20
    n = len(x)        # length

    Simple Trace

    x = [10, 20, 30]
    x[0] = 5
    x.append(40)
    x.insert(1, 15)
    StepValue of x
    Start[10, 20, 30]
    x[0] = 5[5, 20, 30]
    x.append(40)[5, 20, 30, 40]
    x.insert(1, 15)[5, 15, 20, 30, 40]

    The key idea is that the list changes in place. No new list is created by these operations.

    Python Data Structures: Lists, Sets and Dictionaries: Solved Questions with Step-by-Step Explanations (2 Problems)

    Question 1 · Programming, Data Structures and Algorithms · 2025 MCQ
    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|C

    When the above program is executed, at the end, which of the following sets contains "this"?
    1. A.

      Only A

    2. B.

      Only B

    3. C.

      Only C

    4. D.

      A, C

    Correct Answer:

    B

    Step-by-Step Solution

    Insight: This is a set loop tracing question. The critical rule is that in simultaneous assignment, all right-hand side expressions are evaluated using the old values before any assignment occurs.

    Exam route: Trace the sets A, B, and C iteration by iteration. Evaluate the right-hand sides of the assignments using the current state, then update the sets, and finally recheck the loop condition.

    Learning route:

    Initial state: A={"this","that"}, B={"that","other"}, C={"other","this"}

    Iteration 1:

    • Loop condition: "other" in C is True.
    • First if-block: "this" in A is True.

    Evaluate RHS: A-B={"this"}, B-C={"that"}, C-A={"other"}.

    Assign: A={"this"}, B={"that"}, C={"other"}.

    • Second if-block: "that" in B is True.

    Evaluate RHS: C|A={"other","this"}, A|B={"this","that"}, B|C={"that","other"}.

    Assign: A={"other","this"}, B={"this","that"}, C={"that","other"}.

    Iteration 2:

    • Loop condition: "other" in C is True.
    • First if-block: "this" in A is True.

    Evaluate RHS: A-B={"other"}, B-C={"this"}, C-A={"that"}.

    Assign: A={"other"}, B={"this"}, C={"that"}.

    • Second if-block: "that" in B is False. Skip.

    Iteration 3:

    • Loop condition: "other" in C is False (C is {"that"}). Loop terminates.

    Final state: A={"other"}, B={"this"}, C={"that"}.

    The element "this" is present only in set B.

    Question 2 · Programming, Data Structures and Algorithms · 2025 MCQ
    Consider the following Python declarations of two lists.

    A=[1,2,3]
    B=[4,5,6]

    Which one of the following statements results in ?
    1. A.

      A.extend(B)

    2. B.

      A.append(B)

    3. C.

      A.update(B)

    4. D.

      A.insert(B)

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: The question tests the difference between adding an iterable as a single nested object versus flattening its elements into the existing list.

    Exam route: Eliminate options that use non-existent list methods or wrong argument counts. Between the remaining two, recall that extend flattens while append nests.

    Learning route:

    1. A.extend(B): The extend method iterates over the argument B and adds each element (4, 5, 6) one by one to A. The final list is [1, 2, 3, 4, 5, 6]. This matches the requirement.
    2. A.append(B): The append method adds the entire object B as a single element at the end of A. The final list becomes [1, 2, 3, [4, 5, 6]]. This does not match.
    3. A.update(B): The update method is not defined for Python lists (it is used for sets and dictionaries). Calling this raises an AttributeError.
    4. A.insert(B): The insert method requires exactly two arguments: an index and an element. Providing only one argument raises a TypeError.

    Therefore, A.extend(B) is the only statement that produces the desired flat list.

    More previous year questions (pyqs) in this unit