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 `my_list = [1,2,3]; my_list.extend([4,5]); print(my_list)`?
Answer: [1, 2, 3, 4, 5]
`extend()` adds each element of the iterable individually to the list.
Which of the following is a valid way to copy a list without aliasing it?
Answer: Both b and c
Both `.copy()` and `list()` create a new shallow copy of the list.
What does `tuple([1, 2, 3])` return?
Answer: (1, 2, 3)
`tuple()` converts any iterable into a tuple.
What is the output of `s = {1, 1, 2, 2, 3}; print(len(s))`?
Answer: 3
Sets store only unique elements, so duplicates are automatically removed.
What does `my_dict.get('missing', 0)` return if `'missing'` is not in `my_dict`?
Answer: 0
The `get()` method returns the default value (second argument) when the key is absent.
What is the result of `[x**2 for x in range(4)]`?
Answer: [0, 1, 4, 9]
The list comprehension squares each value from 0 to 3.
Which of the following set operations returns elements in the first set but NOT in the second?
Answer: Difference (`-`)
The `-` operator on sets returns elements present in the left set but absent in the right.