ProgrammingVery hardGATE CS · Product-company placement
How many of these statements about CPython are correct? 1. A tuple is hashable only if all its elements are hashable. 2. `x in some_set` is O(1) on average, while `x in some_list` is O(n). 3. A generator expression computes all its values when it is created. 4. `copy.copy` of a list of lists shares the inner lists with the original.
- A. 3
- B. 2
- C. 4
- D. 1
Correct answer: A. 3
1, 2 and 4 are correct: hash(tuple) hashes each element, set lookup is a hash probe, and a shallow copy copies only the outer references. 3 is false: a generator expression is lazy and evaluates only its first iterable up front.
More Python Programming questions
- In CPython, two threads each run a pure-Python CPU-bound loop (no I/O, no C extensions releasing the lock) on a 4-core machine. Compared…
- Which statement about iterables and iterators is correct?
- Assertion (A): After t = (1, 2, [3]), the statement t[2].append(4) succeeds and changes what print(t) shows. Reason (R): A tuple's…
- Which of these expressions raises an exception in Python 3?
- Which statement about the C3 method resolution order is correct for class D(B, C) where both B and C inherit from A?
- Which is the safest way to remove every even number from a list nums in place (so that other references to the same list see the change)?