Data Structures Flashcards
7 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Data Structures flashcards as text
What is the output of `a = [1, 2]; b = a; b.append(3); print(a)`?
Answer: [1, 2, 3]
Both `a` and `b` reference the same list object, so mutating `b` also changes `a`.
What is the correct way to delete a key from a dictionary?
Answer: del dict['key']
The `del` statement with a key subscript removes that key from the dictionary.
What is the output of `print((1, 2) * 2)`?
Answer: (1, 2, 1, 2)
Multiplying a tuple by an integer repeats its contents in a new tuple.
Which method returns and removes an arbitrary element from a set?
Answer: pop()
`set.pop()` removes and returns an arbitrary element from the set.
What is the result of `list({'a': 1, 'b': 2})`?
Answer: ['a', 'b']
Iterating over a dictionary (or converting it with `list()`) yields its keys.
What is the output of `nested = [[1,2],[3,4]]; print(nested[1][0])`?
Answer: 3
`nested[1]` is `[3, 4]` and `[0]` selects its first element, 3.
What does `{1, 2, 3} | {3, 4, 5}` evaluate to?
Answer: {1, 2, 3, 4, 5}
The `|` operator returns the union — all unique elements from both sets.